Exemple #1
0
        public async Task <ActionResult> Create([Bind(Include = "EndDate,Description,Location")] Request request)
        {
            if (ModelState.IsValid)
            {
                request.CreatedDate = DateTime.Now;
                request.CreatorId   = _webSecurity.CurrentUserId;
                request.Completed   = false;

                db.Requests.Add(request);
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            return(View(request));
        }
        public async Task <ActionResult> Edit([Bind(Include = "ResourceId,EntryMade,PersonId,Description,StartOfAvailability,EndOfAvailability,Location,Qty,Status,DisasterId,ResourceTypeId")] Resource resource)
        {
            if (resource.Status == ResourceStatus.All)
            {
                ModelState.AddModelError("Status", "You must select a status other than 'All'.");
            }

            if (resource.StartOfAvailability > resource.EndOfAvailability)
            {
                ModelState.AddModelError("StartOfAvailability", "The start of the availability for this resource cannot be after the end of its availability.");
            }

            if (ModelState.IsValid)
            {
                db.Entry(resource).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }

            ViewBag.DisasterId     = new SelectList(db.Disasters, "Id", "Name", resource.DisasterId);
            ViewBag.PersonId       = new SelectList(db.Persons, "Id", "FirstName", resource.PersonId);
            ViewBag.ResourceTypeId = new SelectList(db.ResourceTypes, "ResourceTypeId", "TypeName", resource.ResourceTypeId);
            return(View(resource));
        }
 public async Task AddResourceAsync(Resource newResource)
 {
     context.Resources.Add(newResource);
     await context.SaveChangesAsync();
 }