public ModelResponse Post(UserInfo user, ref OfficeVm vm) { 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) { return(new ModelResponse(101)); } //Validations if (vm.Title.IsNullOrWhiteSpace() || vm.Address.IsNullOrWhiteSpace() || vm.District.IsNullOrWhiteSpace() || string.IsNullOrWhiteSpace(vm.Telephone) || string.IsNullOrWhiteSpace(vm.Hotline)) { return(new ModelResponse(1)); } //Save to DB if (string.IsNullOrWhiteSpace(vm.Mobile)) { vm.Mobile = ""; } Repo.Post(ref vm, user.UserId); } catch (Exception ex) { return(new ModelResponse(ex)); } return(new ModelResponse(0, vm.OfficeId)); }
public static object Post(OfficeVm data) { if (data.OfficeId > 0) { if (Utils.CheckPermission(3, 91, Utils.LoggedUser.Roles) < 1) { return(Utils.ServiceResponse(PageCode, new ModelResponse(101), null)); } } else { if (Utils.CheckPermission(2, 91, Utils.LoggedUser.Roles) < 1) { return(Utils.ServiceResponse(PageCode, new ModelResponse(101), null)); } } var mr = Mgr.Post(Utils.LoggedUser, ref data); return(Utils.ServiceResponse(PageCode, mr)); }
public long Post(ref OfficeVm vm, string userId) { using (var db = new LMISEntities()) using (var transaction = db.Database.BeginTransaction()) { try { var id = vm.OfficeId; if (id > 0) //Update { var tr = db.Offices .Where(r => r.IsDeleted == null && r.ID == id) .ToList().Single(); tr.Telephone = vm.Telephone; tr.Mobile = vm.Mobile; tr.Fax = vm.Fax; tr.Hotline = vm.Hotline; tr.UpdateUserID = userId; tr.UpdateDate = DateTime.UtcNow; //Delete detail records var dr = db.OfficeDetails .Where(r => r.OfficeID == id) .ToList(); db.OfficeDetails.RemoveRange(dr); } else //Insert { var tr = new Office { Telephone = vm.Telephone, Mobile = vm.Mobile, Fax = vm.Fax, Hotline = vm.Hotline, PostUserID = userId, PostDate = DateTime.UtcNow }; db.Offices.Add(tr); db.SaveChanges(); vm.OfficeId = (long)tr.ID; } //Insert detail records var ds = Utils.MultilingualDataSet( new Dictionary <string, GlobalString> { { "c1", vm.Title }, { "c2", vm.Address }, { "c3", vm.District } }); foreach (var r in ds) { db.OfficeDetails.Add(new OfficeDetail() { OfficeID = vm.OfficeId, LangID = r["c1"].L, Title = r["c1"].T, Address = r["c2"].T, District = r["c3"].T }); } db.SaveChanges(); transaction.Commit(); } catch (Exception ex) { transaction.Rollback(); ExceptionDispatchInfo.Capture(ex).Throw(); } } return(vm.OfficeId); }