Example #1
0
 public ActionResult Edit(Violation violation)
 {
     context.Violations.Attach(violation);
     context.Entry(violation).State = EntityState.Modified;
     context.SaveChanges();
     return RedirectToAction("Details", new { id = violation.Id });
 }
Example #2
0
        public ActionResult Create(CreateViolationViewModel createViolationViewModel)
        {
            int mainViolationId = Convert.ToInt32(createViolationViewModel.MainViolationType);
            int subViolationId = Convert.ToInt32(createViolationViewModel.SubViolationType);
            Violation violation = new Violation();
            violation.MainType = createViolationViewModel.MainViolationType;
            violation.SubType = createViolationViewModel.SubViolationType;
            violation.CreationDateTime = DateTime.Now;
            ViolationPicture violationPicture = new ViolationPicture();
            violationPicture = ImageHelper.SavePic(createViolationViewModel.VImage, HttpContext, violationPicture) as ViolationPicture;
            violation.ViolationPictures.Add(violationPicture);
            violation.Severity = createViolationViewModel.Severity;
            violation.Latitude = createViolationViewModel.Latitude;
            violation.Longtitude = createViolationViewModel.Longitude;
            violation.Title = createViolationViewModel.Title;
            violation.Description = createViolationViewModel.Description;
            violation.Address = createViolationViewModel.Address;
            violation.ViewCount = 0;
            violation.Status = Status.NotSolved;
            violation.ExternalMediaStorage = createViolationViewModel.ExternalMediaStorage;
            violation.MainViolationName = context.ViolationMainTypes.Where(x => x.Id == mainViolationId).FirstOrDefault().Name;
            violation.SubViolationName = context.ViolationSubTypes.Where(x => x.Id == subViolationId).FirstOrDefault().Name;
            var userID = User.Identity.GetUserId();
            if (createViolationViewModel.DynamicValue != null)
            {
                violation.HasDynamic = true;
                string[] stringArray = (string[])createViolationViewModel.DynamicValue;
                string dynamicValue = stringArray[0];
                violation.DynamicValue = dynamicValue;
                violation.DynamicName = createViolationViewModel.DynamicName;
            }
            else
            {
                violation.HasDynamic = false;
            }

            if (!string.IsNullOrEmpty(userID))
            {
                var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
                var currentUser = manager.FindById(User.Identity.GetUserId());
                violation.CreatorUser = currentUser;
            }

            context.Violations.Add(violation);
            context.SaveChanges();
            return RedirectToAction("Index", "Home");
        }