public ActionResult CommentsToServicesForEdit(string serviceName) { //; using (var context = new ApplicationDbContext()) { ViewBag.Services = context.Services.Select(e => e.Name).Where(e => e != "" && e != null).ToList(); } var entry = new CommentToService { ServiceName = serviceName }; //if (position > 0) //{ // var employee = repositoryPeople.GetPositions() // .FirstOrDefault((p) => // p.Id == position // ) // .People // .ToList() // .Select((p) => new ModelForEvent // { // Id = p.Id, // Position = p.Name, // Name = p.Name + " " + p.Surname // }) // .ToList(); // if (employee != null) // return PartialView(employee); //} return(PartialView( new List <CommentToService> { entry })); }
public override void UpdateCommentToService(CommentToService model) { throw new NotImplementedException(); //if (model == null) return; //if (model.Id == 0) return; ////context.Responsibles.Add(model); //else //{ // var dbEntry = context.Responsibles.FirstOrDefault( r => r.Id == model.Id); // if (dbEntry != null) // { // dbEntry.Position = model.Position; // } // else // { // //throw new Exception("Record didn't found"); // } //} //context.SaveChanges(); }
public abstract void UpdateCommentToService(CommentToService model);
public ActionResult Edit(/*Event dbEntry*/) { if (Request.Form.Count <= 0)// .Content.IsMimeMultipartContent()) { throw new System.Web.Http.HttpResponseException(HttpStatusCode.UnsupportedMediaType); } //string root = HttpContext.Current.Server.MapPath("~/App_Data"); //var provider = new System.Net.Http.MultipartFormDataStreamProvider(root); Event dbEntry;// = new Event(); foreach (var key in Request.Form.AllKeys) { foreach (var val in Request.Form.GetValues(key)) { Trace.WriteLine(string.Format("{0}: {1}", key, val)); } } //------------------------------------------------------------------- int id; int.TryParse(Request.Form.GetValues("Id").FirstOrDefault(), out id); //------------------------------------------------------------------- var datTimeMass = Request.Form.GetValues("Start"); var start = DateTime.Parse(datTimeMass[0]); //new DateTime() //------------------------------------------------------------------- int duration; int.TryParse(Request.Form.GetValues("Duration").FirstOrDefault(), out duration); //------------------------------------------------------------------- dbEntry = new Event { Id = id, Access = Request.Form.GetValues("Access").FirstOrDefault(), Location = Request.Form.GetValues("Location").FirstOrDefault(), EventType = Request.Form.GetValues("EventType").FirstOrDefault(), Title = Request.Form.GetValues("Title").FirstOrDefault(), Start = start, Duration = duration, Description = Request.Form.GetValues("Description").FirstOrDefault(), //Responsibles = { }, //CommentsToServices = { } }; // Get Responsibles var responsibleIds = Request.Form.GetValues("responsibleId"); var responsibleNames = Request.Form.GetValues("ResponsibleName"); var hidenParamsPost = Request.Form.GetValues("hidenParamPost"); var hidenParamsName = Request.Form.GetValues("hidenParamName"); var comments = Request.Form.GetValues("Comment"); for (int i = 0; i < responsibleIds?.Length; i++) { int responsibleId; if (string.IsNullOrEmpty(responsibleIds[i]) || string.IsNullOrWhiteSpace(responsibleIds[i])) { responsibleId = 0; } else { int.TryParse(responsibleIds[i], out responsibleId); } int positionId; if (string.IsNullOrEmpty(hidenParamsPost[i]) || string.IsNullOrWhiteSpace(hidenParamsPost[i])) { positionId = 0; } else { int.TryParse(hidenParamsPost[i], out positionId); } int personId; if (string.IsNullOrEmpty(hidenParamsName[i]) || string.IsNullOrWhiteSpace(hidenParamsName[i])) { personId = 0; } else { int.TryParse(hidenParamsName[i], out personId); } Responsible responsible = new Responsible { Id = responsibleId, EventId = id, Comment = comments[i], PositionId = positionId, PersonName = responsibleNames[i], }; if (personId > 0) { responsible.PersonId = personId; } //else responsible.PersonId = null; dbEntry.Responsibles.Add(responsible); } // Get CommentToService var serviceNames = Request.Form.GetValues("serviceName"); var serviceComments = Request.Form.GetValues("serviceComment"); for (int i = 0; i < serviceNames?.Length; i++) { var commentToService = new CommentToService(); if (!string.IsNullOrEmpty(serviceNames[i]) || !string.IsNullOrWhiteSpace(serviceNames[i])) { //int.TryParse(serviceNames[i], out responsibleId); commentToService.ServiceName = serviceNames[i]; } if (!string.IsNullOrEmpty(serviceComments[i]) || !string.IsNullOrWhiteSpace(serviceComments[i])) { commentToService.Comment = serviceComments[i]; } commentToService.EventId = dbEntry.Id; dbEntry.CommentsToServices.Add(commentToService); } //------------------------------------------------------------------- bool serverValidation = false; if (dbEntry != null && !string.IsNullOrWhiteSpace(dbEntry.Title) && !string.IsNullOrWhiteSpace(dbEntry.Location) && validData(dbEntry.Start, true) //&& (dbEntry.Duration > 0 && dbEntry.Duration < 1440) //&& validEmployees(dbEntry.Responsible, true) && validationCreateSchedule(dbEntry) ) { serverValidation = true; } if (serverValidation && ModelState.IsValid) { try { repositoryEvent.Update(dbEntry); } catch (Exception) { return(new HttpNotFoundResult()); } TempData["Message"] = string.Format($"The change was saved for the event \"{dbEntry.Title}\""); //IEnumerable<Event> schedule = repositoryEvent.GetEvents(); return(Redirect("Schedule")); } else { ViewBag.Location = repositoryEvent.GetEvents().Select(e => e.Location).Distinct(); ViewBag.TypeEvent = repositoryEvent.GetEvents().Select(e => e.EventType).Distinct().Where(e => e != ""); ViewBag.TitleEvent = repositoryEvent.GetEvents().Select(e => e.Title).Distinct(); ViewBag.Positions = repositoryPeople.GetPositions().ToList(); using (var context = new ApplicationDbContext()) { ViewBag.Services = context.Services.Select(e => e.Name).Where(e => e != "" && e != null).ToList(); } return(View(dbEntry)); } //bool validEmployees(string value, EPosition pos, bool required = false) //{ // if (string.IsNullOrEmpty(value))// check empty // { // if (required) return false; // else return true; // } // int val; // if (int.TryParse(value, out val))// check numbers // { // var person = repositoryPeople.GetPerson(val); // List<Position> item = person.Positions.ToList(); // for (int i = 0; i < item.Count; i++) // { // if (item[i].Name == pos.ToString()) return true; // } // return false; // } // else // check symbol // { // Regex r = new Regex(@"[\[\]{}\d!#\^$.,|\/\\?*@+()]"); // Match m = r.Match(value); // if (m == null || m.Length > 0) // { // ModelState.AddModelError("", "Field can't have \"[[]{}d!#\\^$|\\/\\?*@+()]\" symbols."); // return false; // } // else return true; // } //} }