public List <Models.Services> GetVendorsByServiceName(string name) { List <Models.Services> listobj = new List <Models.Services>(); try { var repobj = _VendorFacade.GetVendorsByServiceName(name); if (repobj != null) { foreach (var service in repobj) { var iter = new Models.Services { Id = service.Id, Name = service.Name, Vendorid = service.Vendorid, Price = service.Price }; listobj.Add(iter); } } } catch (Exception e) { listobj = null; throw e; } return(listobj); }
public async Task <IActionResult> AddEdit(string id, Models.Services model, string redirectUrl) { if (ModelState.IsValid) { if (String.IsNullOrWhiteSpace(id)) { _context.Add(model); await _context.SaveChangesAsync(); TempData["Notification"] = Notification.ShowNotif(MessageType.Add, ToastType.Green); return(PartialView("_SuccessfulResponse", redirectUrl)); } _context.Update(model); await _context.SaveChangesAsync(); TempData["Notification"] = Notification.ShowNotif(MessageType.Edit, ToastType.Blue); return(PartialView("_SuccessfulResponse", redirectUrl)); } return(PartialView("AddEdit", model)); }
private IEnumerable <ServiceProperties> UpdateExProperties(Models.Services newService, Models.Services exService) { //replacing newService old properties with new ones var newProperties = newService.ServiceProperties.ToList(); var oldProperties = exService.ServiceProperties.ToList(); exService.ServiceProperties = null; foreach (var property in oldProperties) { var isPropertyExist = newService.ServiceProperties.FirstOrDefault(x => x.Id == property.Id); if (isPropertyExist != null) //update old properties info { property.Title = isPropertyExist.Title; property.Code = isPropertyExist.Code; newProperties.Remove(isPropertyExist); } else //remove oldProperties that doesnt exist in new properties { property.Deleted = true; } _context.ServiceProperties.Update(property); } return(newProperties); }
public async Task <Models.Services> Add(Models.Services service, Guid userId) { service.RegisterDate = DateTime.Now; service.Status = MyEnums.ServiceStatus.Active; service.UserId = userId; await _context.Services.AddAsync(service); await _context.SaveChangesAsync(); return(service); }
public async Task <bool> UpdateService(Guid id, Models.Services service, Guid userId) { var preService = await GetById(id, userId); var newProperties = UpdateExProperties(service, preService); AddNewPropertiesToService(id, newProperties); preService.Title = service.Title; _context.Services.Update(preService); await _context.SaveChangesAsync(); return(true); }
public IActionResult Services(int[] subevents) { try { if (subevents != null) { List <Services> list = new List <Services>(); foreach (var id in subevents) { var query = (from s in db.Services join es in db.EventServices on s.SId equals es.SId join se in db.SubEvents on es.SeId equals se.SeId where se.SeId == id && s.SIsAvailable == true select new { s }); foreach (var q in query) { Services s = new Models.Services { SId = q.s.SId, SName = q.s.SName.TrimEnd(), SPrice = q.s.SPrice, SDp = q.s.SDp.TrimEnd(), SIsAvailable = q.s.SIsAvailable, SDetail = q.s.SDetail.TrimEnd() }; list.Add(s); } } ViewBag.Cart = getCountOfCart(); var newList = RemoveDuplicates(list); return(View("Services", newList)); } else { return(NoContent()); } } catch (Exception) { return(Forbid()); } }
public string UpdateServices([FromBody] Models.Services service) { var str = "Update service failed in Controller method"; try { EFModels.Vendorservices cartb = new EFModels.Vendorservices() { Id = service.Id, Name = service.Name, Vendorid = service.Vendorid, Price = service.Price }; str = _VendorFacade.UpdateServices(cartb); } catch (Exception e) { str = e.Message; throw e; } return(str); }
public string AddServices([FromBody] Models.Services service) { var status = "could not add services"; try { EFModels.Vendorservices cartb = new EFModels.Vendorservices() { Name = service.Name, Vendorid = service.Vendorid, Price = service.Price, }; status = _VendorFacade.AddServices(cartb); } catch (Exception e) { status = e.Message; throw e; } return(status); }
public string DeleteCart([FromBody] Models.Services service) { var str = string.Empty; try { EFModels.Vendorservices cartb = new EFModels.Vendorservices() { Id = service.Id, Name = service.Name, Vendorid = service.Vendorid, Price = service.Price }; str = _VendorFacade.DelServices(cartb); } catch (Exception e) { str = e.Message; throw e; } return(str); }