public IActionResult Upsert(int?id) { EventVm eventVm = new EventVm() { Event = new Event(), MovieList = _unitOfWork.Movie.GetAll().Select(i => new SelectListItem { Text = i.Title, Value = i.Id.ToString() }), HallList = _unitOfWork.Hall.GetAll().Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }) }; if (id == null) { return(View(eventVm)); } eventVm.Event = _unitOfWork.Event.Get(id.GetValueOrDefault()); if (eventVm.Event == null) { return(NotFound()); } return(View(eventVm)); }
public async Task <IActionResult> Create(EventVm e, int eventCategory, int eventSpeaker) // VM => Evenet, Detail, Category, Speaker { ViewBag.Categories = await _context.Categories.Where(c => c.IsDeleted == false).ToListAsync(); ViewBag.Speaker = await _context.Speakers.ToListAsync(); //if (!e.Photo.IsSelectedType("image/")){ // ModelState.AddModelError("Photo", "Not image type"); // return View(); //}; string path = Path.Combine("img", "event"); Event newEvent = new Event { Day = e.Day, StartTime = e.StartTime, Endtime = e.Endtime, Location = e.Location, EventName = e.EventName, CategoryId = eventCategory, IsDeleted = false, Image = await e.Photo.SaveImageAsync(_env.WebRootPath, path) }; await _context.Events.AddAsync(newEvent); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); }
public ActionResult Create(EventVm vm) { try { if (!ModelState.IsValid) { //var errors = new List<ModelError>(); //foreach (var value in ModelState.Values) { // foreach (var error in value.Errors) { // errors.Add(error); // } //} //TempData["CreateErrors"] = errors; return(RedirectToAction("Create")); } vm.Comment = EncodeText(vm.Comment); Guid userId = new Guid(User.Identity.GetUserId()); vm.UserId = userId; if (vm.File != null) { var fileName = vm.File.FileName; vm.ImageUrl = Path.Combine("\\Uploads", fileName); // local storage var path = Path.Combine(Server.MapPath("~/Uploads/"), fileName); vm.File.SaveAs(path); } //List<int> servicesIds = new List<int>(); //if(vm.ServicesSource != null) //{ // foreach (var service in vm.ServicesSource) // { // if (service.IsSelected) // { // servicesIds.Add(service.Id); // } // } //} List <int> servicesIds = vm.ServicesSource.Where(s => s.IsSelected).Select(s => s.Id).ToList(); vm.ServicesIds = servicesIds; var model = new Event(); model.Create(vm); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create() { List <TypeVm> places = new Event().GetPlaces(); List <TypeVm> eventTypes = new Event().GetAllEventTypes(); List <ServiceItemVm> servicesSource = new Event().GetAllServices(); var vm = new EventVm(); vm.Places = places; vm.EventTypes = eventTypes; vm.ServicesSource = servicesSource; vm.EventTypeId = eventTypes.First().Id; return(View(vm)); }
public bool IsDuplicate(ref EventVm vm) { var id = vm.EventId; var startDate = vm.StartDate; var titles = vm.Title.ToLowerTrimmedStrings(); using (var db = new LMISEntities()) { return(db.Events .Include(r => r.EventsDetails) .Any(r => r.IsDeleted == null && r.EventId != id && r.StartDate == startDate && r.EventsDetails .Any(d => titles.Contains(d.EventTitle.Trim().ToLower())))); } }
public EventVm Init(long userId, long id) { //Get current user var user = BlUser.LoadSingle(userId); var eventLog = LoadSingle(userId, id); var toRet = new EventVm { Module = eventLog.Module.Id, Action = eventLog.Action, Text = eventLog.Text, UserName = BlUser.LoadSingle(eventLog.UserId).UserName, Branch = BlBranch.GetBranchName(user.Id, eventLog.BranchId), Date = eventLog.EntryDate.ToString(true) }; return(toRet); }
public IActionResult Upsert(EventVm eventVm) { if (ModelState.IsValid) { if (eventVm.Event.Id == 0) { _unitOfWork.Event.Add(eventVm.Event); } else { _unitOfWork.Event.Update(eventVm.Event); } _unitOfWork.Save(); return(RedirectToAction(nameof(Index))); } else { eventVm.MovieList = _unitOfWork.Movie.GetAll().Select(i => new SelectListItem { Text = i.Title, Value = i.Id.ToString() }); eventVm.HallList = _unitOfWork.Hall.GetAll().Select(i => new SelectListItem { Text = i.Name, Value = i.Id.ToString() }); if (eventVm.Event.Id != 0) { eventVm.Event = _unitOfWork.Event.Get(eventVm.Event.Id); } } return(View(eventVm)); }
public static object Post(EventVm data, bool validateOnly) { if (DalFactory.Singleton.DataService.IsAdmin(Utils.LoggedUser.UserId)) { if (data.EventId > 0) { if (Utils.CheckPermission(3, 93, Utils.LoggedUser.Roles) < 1) { return(Utils.ServiceResponse(PageCode, new ModelResponse(101), null)); } } else { if (Utils.CheckPermission(2, 93, Utils.LoggedUser.Roles) < 1) { return(Utils.ServiceResponse(PageCode, new ModelResponse(101), null)); } } } var mr = Mgr.Post(Utils.LoggedUser, ref data, Utils.UploadFolder, validateOnly); return(Utils.ServiceResponse(PageCode, mr)); }
public long Post(ref EventVm vm, string userId) { using (var db = new LMISEntities()) using (var transaction = db.Database.BeginTransaction()) { try { var id = vm.EventId; if (id > 0) //Update { var tr = db.Events .Where(r => r.IsDeleted == null && r.EventId == id) .ToList().Single(); tr.OrganizationContactID = vm.ContactId; tr.StartDate = vm.StartDate.AsUtc(); tr.EndDate = vm.EndDate.AsUtc(); tr.EventTypeID = vm.Type; tr.Price = vm.Price; tr.EventContactTelephone = vm.ContactTelephone; tr.EventContactWebsite = vm.ContactWebsite; tr.UploadPath = vm.FilePath; tr.IsInternal = vm.IsInternal; tr.IsInformal = vm.IsInformal; tr.IsApproved = (byte)vm.Approval; tr.UpdateUserID = userId; tr.UpdateDate = DateTime.UtcNow; //Delete detail records var dr = db.EventsDetails .Where(r => r.EventId == id) .ToList(); db.EventsDetails.RemoveRange(dr); } else //Insert { var tr = new Event { OrganizationContactID = vm.ContactId, StartDate = vm.StartDate.AsUtc(), EndDate = vm.EndDate.AsUtc(), EventTypeID = vm.Type, Price = vm.Price, EventContactTelephone = vm.ContactTelephone, EventContactWebsite = vm.ContactWebsite, UploadPath = vm.FilePath, IsInternal = vm.IsInternal, IsInformal = vm.IsInformal, IsApproved = (byte)vm.Approval, PostUserID = userId, PostDate = DateTime.UtcNow, RejectReason = "" }; db.Events.Add(tr); db.SaveChanges(); vm.EventId = (long)tr.EventId; } //Insert detail records var ds = Utils.MultilingualDataSet( new Dictionary <string, GlobalString> { { "c1", vm.Title }, { "c2", vm.Address }, { "c3", vm.ContactAddress } }); foreach (var r in ds) { var dr = new EventsDetail() { EventId = vm.EventId, LanguageID = r["c1"].L, EventTitle = r["c1"].T, EventAddress = r["c2"].T, EventContactAddress = r["c3"].T }; db.EventsDetails.Add(dr); } db.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); ExceptionDispatchInfo.Capture(ex).Throw(); } } return(vm.EventId); }
public EventHandler(EventVm eventVm) { EventVm = eventVm; }
public ModelResponse Post(UserInfo user, ref EventVm vm, string fileFolder, bool validateOnly) { try { //Authorization if (user == null) { return(new ModelResponse(101)); } if (string.IsNullOrWhiteSpace(user.UserId)) { return(new ModelResponse(101)); } if (!user.IsApproved || user.IsIndividual || user.OrgContactId == null) { return(new ModelResponse(101)); } var isAdmin = DalFactory.Singleton.DataService.IsAdmin(user.UserId); if (isAdmin && vm.EventId > 0 && !Repo.IsInternal(vm.EventId)) { return(new ModelResponse(101)); } if (!isAdmin && vm.EventId > 0 && !Repo.IsByOrgContact(vm.EventId, (long)user.OrgContactId)) { return(new ModelResponse(101)); } //Validations if (vm.Title.IsNullOrWhiteSpace() || vm.Address.IsNullOrWhiteSpace() || string.IsNullOrWhiteSpace(vm.Type) || vm.Price < 0 || vm.ContactAddress.IsNullOrWhiteSpace() || string.IsNullOrWhiteSpace(vm.ContactTelephone) || string.IsNullOrWhiteSpace(vm.ContactWebsite)) { return(new ModelResponse(1)); } if ((vm.EventId < 1 && vm.StartDate < DateTime.Today) || vm.EndDate < vm.StartDate) { return(new ModelResponse(2)); } if (Repo.IsDuplicate(ref vm)) { return(new ModelResponse(3)); } if (!validateOnly) { //Verify File Path if (string.IsNullOrWhiteSpace(fileFolder)) { return(new ModelResponse(102)); } if (string.IsNullOrWhiteSpace(vm.FilePath)) { return(new ModelResponse(102)); } if (!File.Exists(Path.Combine(fileFolder, vm.FilePath))) { return(new ModelResponse(102)); } //Save to DB vm.Approval = isAdmin ? Approval.Approved : Approval.Pending; if (!isAdmin) { vm.IsInformal = false; } vm.IsInternal = isAdmin; vm.ContactId = (long)user.OrgContactId; Repo.Post(ref vm, user.UserId); } } catch (Exception ex) { return(new ModelResponse(ex)); } return(new ModelResponse(0, vm.EventId)); }
public EventVm UpdateEvent([FromBody] EventVm model) { return(GetBusinessLayerProxy(User).UpdateEvent(model)); }
public void RemoveEvent(EventVm item) { Events.Remove(item); OnPropertyChanged("Totals"); }
public void AddEvent(EventVm item) { Events.Add(item); OnPropertyChanged("Totals"); }
public void Create(EventVm vm) { EventDb.Create(vm.Start, vm.End, vm.EventTypeId, vm.PlaceId, vm.UserId, vm.ImageUrl, vm.ServicesIds, vm.Comment); }