Search Results

Search found 42 results on 2 pages for 'fearofawhackplanet'.

Page 1/2 | 1 2  | Next Page >

  • MVC map to nullable bool in model

    - by fearofawhackplanet
    With a view model containing the field: public bool? IsDefault { get; set; } I get an error when trying to map in the view: <%= Html.CheckBoxFor(model => model.IsDefault) %> Cannot implicitly convert type 'bool?' to 'bool'. An explicit conversion exists (are you missing a cast?) I've tried casting, and using .Value and neither worked. Note the behaviour I would like is that submitting the form should set IsDefault in the model to true or false. A value of null simply means that the model has not been populated.

    Read the article

  • MVC Ajax.ActionLink doesn't find POST method

    - by fearofawhackplanet
    I have a POST method declared in my controller: [AcceptVerbs(HttpVerbs.Post)] public ActionResult UpdateComments(int id, string comments) { // ... } and an ActionLink in my view: <%= Ajax.ActionLink("update", "UpdateComments", new { id = Model.Id, comments = "test" }, new AjaxOptions { HttpMethod="POST", OnFailure="alert('fail');", OnSuccess = "alert('success');" })%> I get a "not found" error when it tries to route this request. If I remove the POST restriction from the UpdateComments method in the controller, it works fine. What am I missing?

    Read the article

  • Configuring Unity with a closed generic constructor parmater

    - by fearofawhackplanet
    I've been trying to read the article here but I still can't understand it. I have a constructor resembling the following: IOrderStore orders = new OrderStore(new Repository<Order>(new OrdersDataContext())); The constructor for OrderStore: public OrderStore(IRepository<Order> orderRepository) Constructor for Repository<T>: public Repository(DataContext dataContext) How do I set this up in the Unity config file? UPDATE: I've spent the last few hours banging my head against this, and although I'm not really any closer to getting it right I think at least I can be a little more specific about the problem. I've got my IRespository<T> working ok: <typeAlias alias="IRepository" type="MyAssembly.IRepository`1, MyAssembly" /> <typeAlias alias="Repository" type="MyAssembly.Repository`1, MyAssembly" /> <typeAlias alias="OrdersDataContext" type="MyAssembly.OrdersDataContext, MyAssembly" /> <types> <type type="OrdersDataContext"> <typeConfig> <constructor /> <!-- ensures paramaterless constructor used --> </typeConfig> </type> <type type="IRepository" mapTo="Repository"> <typeConfig> <constructor> <param name="dataContext" parameterType="OrdersDataContext"> <dependency /> </param> </constructor> </typeConfig> </type> </types> So now I can get an IRepository like so: IRepository rep = _container.Resolve(); and that all works fine. The problem now is when trying to add the configuration for IOrderStore <type type="IOrderStore" mapTo="OrderStore"> <typeConfig> <constructor> <param name="ordersRepository" parameterType="IRepository"> <dependency /> </param> </constructor> </typeConfig> </type> When I add this, Unity blows up when trying to load the config file. The error message is OrderStore does not have a constructor that takes the parameters (IRepository`1). What I think this is complaining about is because the OrderStore constructor takes a closed IRepository generic type, ie OrderStore(IRepository<Order>) and not OrderStore(IRepository<T>) I don't have any idea how to resolve this.

    Read the article

  • Returning IEnumerable from an indexer, bad practice?

    - by fearofawhackplanet
    If I had a CarsDataStore representing a table something like: Cars -------------- Ford | Fiesta Ford | Escort Ford | Orion Fiat | Uno Fiat | Panda Then I could do IEnumerable<Cars> fords = CarsDataStore["Ford"]; Is this a bad idea? It's iconsistent with the other datastore objects in my api (which all have a single column PK indexer), and I'm guessing most people don't expect an indexer to return a collection in this situation.

    Read the article

  • how to visualise/debug an imagemap?

    - by fearofawhackplanet
    I'm dynamically generating an imagemap for a chart tool I have. I was hoping to be able to set a border or color on the area tags so I could check everything was being generated with the right coords, but a little research shows this is not possible. So whats the easiest way to check my image map is correct? Are there any browser tools which will "visualise" the areas?

    Read the article

  • Use of IsAssignableFrom and "is" keyword in C#

    - by fearofawhackplanet
    While trying to learn Unity, I keep seeing the following code for overriding GetControllerInstance in MVC: if(!typeof(IController).IsAssignableFrom(controllerType)) { ... } this seems to me a pretty convoluted way of basically writing if(controllerType is IController) { ... } I appreciate there are subtle differences between is and IsAssignableFrom, ie IsAssignableFrom doesn't include cast conversions, but I'm struggling to understand the implication of this difference in practical scenarios. When is it imporantant to choose IsAssignableFrom over is? What difference would it make in the GetControllerExample? if (!typeof(IController).IsAssignableFrom(controllerType)) throw new ArgumentException(...); return _container.Resolve(controllerType) as IController;

    Read the article

  • Replace image in word doc using OpenXML

    - by fearofawhackplanet
    Following on from my last question here OpenXML looks like it probably does exactly what I want, but the documentation is terrible. An hour of googling hasn't got me any closer to figuring out what I need to do. I have a word document. I want to add an image to that word document (using word) in such a way that I can then open the document in OpenXML and replace that image. Should be simple enough, yes? I'm assuming I should be able to give my image 'placeholder' an id of some sort and then use GetPartById to locate the image and replace it. Would this be the correct method? What is this Id? How do you add it using Word? Every example I can find which does anything remotely similar starts by building the whole word document from scratch in ML, which really isn't a lot of use. EDIT: it occured to me that it would be easier to just replace the image in the media folder with the new image, but again can't find any indication of how to do this.

    Read the article

  • using indexer to retrieve Linq to SQL object from datastore

    - by fearofawhackplanet
    class UserDatastore : IUserDatastore { ... public IUser this[Guid userId] { get { User user = (from u in _dataContext.Users where u.Id == userId select u).FirstOrDefault(); return user; } } ... } One of the developers in our team is arguing that an indexer in the above situation is not appropriate and that a GetUser(Guid id) method should be prefered. The arguments being that: 1) We aren't indexing into an in-memory collection, the indexer is basically performing a hidden SQL query 2) Using a Guid in an indexer is bad (FxCop flagged this also) 3) Returning null from an indexer isn't normal behaviour 4) An API user generally wouldn't expect any of this behaviour I agree to an extent with (most of) these points. But I'm also inclined to argue that one of the characteristics of Linq is to abstract the database access to make it appear that you're simply working with a bunch of collections, even though the lazy evaluation paradigm means those collections aren't evaluated until you run a query over them. It doesn't seem inconsistent to me to access the datastore in the same manner as if it was a concrete in-memory collection here. Also bearing in mind this is an inherited codebase which uses this pattern extensively and consistently, is it worth the refactoring? I accept that it might have been better to use a Get method from the start, but I'm not yet convinced that it's completely incorrect to be using an indexer. I'd be interested to hear all opinions, thanks.

    Read the article

  • How to learn as a lone developer?

    - by fearofawhackplanet
    I've been lucky to work in a small team with a couple of experienced and knowledgeable developers for the first year of my career. I've learned a huge amount. But I'm now getting transferred within my company, and will be working on solo projects. I'll cope, but I know I'll make mistakes and won't always produce the best solutions without someone to guide me and review my output. I'm wondering if anyone has any tips in this situation. How can I keep learning? What's the best way to monitor and asses the quality of my work? How can I ensure that my career and skills don't stagnate?

    Read the article

  • Does MS Test provide a default value equals comparison?

    - by fearofawhackplanet
    I want to test for example int orderId = myRepository.SubmitOrder(orderA); orderB = myRepository.GetOrder(orderId); Assert.AreEqual(orderA, orderB); // fail Obviously I need a value comparison here, but I don't want to have to provide an overridden Equals implementation for all of my classes purely for the sake of testing (it wouldn't be of any use in the rest of the app). Is there a provided generic method that just checks every field using reflection? Or if not, it is possible to write my own?

    Read the article

  • Can't select View Content dropdown when adding view in MVC using Interfaces

    - by fearofawhackplanet
    I have my Model defined externally in two projects - a Core project and an Interface project. I am opening the Add View dialogue from my controller, and selecting Create a strongly typed view. In the drop down list, I can select the concrete types like MyProject.Model.Core.OrderDetails, but the interface types like MyProject.Model.Interface.IOrderDetails aren't there. I can type the interface class in manually and everything works, but then the View content menu that lets you select the Create, Delete, List, etc scaffolding is disabled. Is there some problem with using interfaces in MVC? Or is it something else I'm missing?

    Read the article

  • Is testability alone justification for dependency injection?

    - by fearofawhackplanet
    The advantages of DI, as far as I am aware, are: Reduced Dependencies More Reusable Code More Testable Code More Readable Code Say I have a repository, OrderRepository, which acts as a repository for an Order object generated through a Linq to Sql dbml. I can't make my orders repository generic as it performs mapping between the Linq Order entity and my own Order POCO domain class. Since the OrderRepository by necessity is dependent on a specific Linq to Sql DataContext, parameter passing of the DataContext can't really be said to make the code reuseable or reduce dependencies in any meaningful way. It also makes the code harder to read, as to instantiate the repository I now need to write new OrdersRepository(new MyLinqDataContext()) which additionally is contrary to the main purpose of the repository, that being to abstract/hide the existence of the DataContext from consuming code. So in general I think this would be a pretty horrible design, but it would give the benefit of facilitating unit testing. Is this enough justification? Or is there a third way? I'd be very interested in hearing opinions.

    Read the article

  • Constraining enum value in method parameter

    - by fearofawhackplanet
    enum Fruit { Banana, Orange, Strawberry ... ... // etc, very long enum } PeelFruit(Fruit.Orange); PeelFruit(Fruit.Banana); PeelFruit(Fruit.Strawberry); // huh? can't peel strawberries! Sorry for the lame example, but hopefully you get the idea. Is there a way to constrain the enum values that PeelFruit will accept? Obvisouly I could check them in the method with a switch or something, but it would be cool if there was a way to do it that is a) a bit more compact, and b) would cause a compile time error, not a run time error. [Fruit = Orange,Bannana] void PeelFruit(Fruit fruit) { ... }

    Read the article

  • Dynamically set generic type argument

    - by fearofawhackplanet
    Following on from my question here, I'm trying to create a generic value equality comparer. I've never played with reflection before so not sure if I'm on the right track, but anyway I've got this idea so far: bool ContainSameValues<T>(T t1, T t2) { if (t1 is ValueType || t1 is string) { return t1.Equals(t2); } else { IEnumerable<PropertyInfo> properties = t1.GetType().GetProperties().Where(p => p.CanRead); foreach (var property in properties) { var p1 = property.GetValue(t1, null); var p2 = property.GetValue(t2, null); if( !ContainSameValues<p1.GetType()>(p1, p2) ) return false; } } return true; } This doesn't compile because I can't work out how to set the type of T in the recursive call. Is it possible to do this dynamically at all? There are a couple of related questions on here which I have read but I couldn't follow them enough to work out how they might apply in my situation.

    Read the article

  • Best architecture for accessing secondary database

    - by fearofawhackplanet
    I'm currently developing an app which will use a Linq to SQL (or possibly EF) data access layer. We already have a database which holds all our Contacts information, but there is currently no API around this. I need to interact with this DB from the new app to retrieve contact details. I can think of two ways I could do this - 1) Develop a suite of web services against the contacts database 2) Write a Linq to SQL (or EF) DAL and API against the contacts database I will probably be developing several further apps in the future which will also need access to the Contacts data. Which would generally be the prefered method? What are the points I need to consider? Am I even asking a sensible question, or am I missing something obvious?

    Read the article

  • Method hiding with interfaces

    - by fearofawhackplanet
    interface IFoo { int MyReadOnlyVar { get; } } class Foo : IFoo { int MyReadOnlyVar { get; set; } } public IFoo GetFoo() { return new Foo { MyReadOnlyVar = 1 }; } Is the above an acceptable way of implementing a readonly/immutable object? The immutability of IFoo can be broken with a temporary cast to Foo. In general (non-critical) cases, is hiding functionality through interfaces a common pattern? Or is it considered lazy coding? Or even an anti-pattern?

    Read the article

  • Link objects as fields in UML diagram

    - by fearofawhackplanet
    I'm trying to generate a diagram for a design document. I've generated a class diagram in VS. At the moment it's just a bunch of unconnected boxes as there isn't any inheritance going on. It feels like it would be more useful if I could show how the objects interact through properties and parameters. As an example, a Boy class has a method Kiss which takes a Girl object. How can I show that Boy and Girl interact by connecting this in the diagram? Is there a notation for this in UML? Or is there another type of diagram that shows this? Can I make VS draw this connection for me somehow? Or is this a silly/useless idea? It just doesn't feel like a proper diagram unless it's got some lines on it somewhere :)

    Read the article

  • Calling DI Container directly in method code (MVC Actions)

    - by fearofawhackplanet
    I'm playing with DI (using Unity). I've learned how to do Constructor and Property injection. I have a static container exposed through a property in my Global.asax file (MvcApplication class). I have a need for a number of different objects in my Controller. It doesn't seem right to inject these throught the constructor, partly because of the high quantity of them, and partly because they are only needed in some Actions methods. The question is, is there anything wrong with just calling my container directly from within the Action methods? public ActionResult Foo() { IBar bar = (Bar)MvcApplication.Container.Resolve(IBar); // ... Bar uses a default constructor, I'm not actually doing any // injection here, I'm just telling my conatiner to give me Bar // when I ask for IBar so I can hide the existence of the concrete // Bar from my Controller. } This seems the simplest and most efficient way of doing things, but I've never seen an example used in this way. Is there anything wrong with this? Am I missing the concept in some way?

    Read the article

  • StreamWriter stops writing when file is opened from web link

    - by fearofawhackplanet
    Following on from my previous question... The following code creates log files on a web server: private void LogMessage(Message msg) { using (StreamWriter sw = File.AppendText(_logDirectory + DateTime.Now.ToString("yyyyMMddHH") + ".txt")) { sw.WriteLine(msg.ToString()); } } The log files are linked to from an admin page on the web site: foreach (FileInfo file in logDir.GetFiles()) { Response.Write("<a href='http:// .... /Logs/" + file.Name + "'>" + file.Name + "</a>"); } I'm getting the problem that after someone looks at one of the log files from the link, that log file stops being written to.

    Read the article

  • StreamWriter not creating new file

    - by fearofawhackplanet
    I'm trying to create a new log file every hour with the following code running on a server. The first log file of the day is being created and written to fine, but no further log files that day get created. Any ideas what might be going wrong? No exceptions are thrown either. private void LogMessage(Message msg) { using (StreamWriter sw = File.AppendText(_logDirectory + DateTime.Today.ToString("yyyyMMddHH") + ".txt")) { sw.WriteLine(msg.ToString()); } }

    Read the article

  • Partial view postback from a standard Html form with MVC

    - by fearofawhackplanet
    I have a file upload button on my MVC view. After the file is uploaded, my FileList partial view on the page should refresh. I tried to upload with Ajax.BeginForm(), but have discovered that Ajax will not submit file data. I've got the file upload working now by using the jQuery Form plugin, which lets you ajaxify the normal Html.BeginForm() submit method. Is is still possible to trigger the partial page update using this method?

    Read the article

  • Html encoding in MVC input

    - by fearofawhackplanet
    I'm working through NerdDinner and I'm a bit confused about the following section... First they've added a form for creating a new dinner, with a bunch of textboxes delcared like: <%= Html.TextArea("Description") %> They then show two ways of binding form input to the model: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create() { Dinner dinner = new Dinner(); UpdateModel(dinner); ... } or: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Create(Dinner dinner) { ... } Ok, great, that all looks really easy so far. Then a bit later on they say: It is important to always be paranoid about security when accepting any user input, and this is also true when binding objects to form input. You should be careful to always HTML encode any user-entered values to avoid HTML and JavaScript injection attacks Huh? MVC is managing the data binding for us. Where/how are you supposed to do the HTML encoding?

    Read the article

1 2  | Next Page >