public EmployersTrainingProvidersVM Post(EmployersTrainingProvidersVM vm, string userId) { using (var db = new LMISEntities()) { try { var id = vm.ID; var checkExist = db.EmployersTrainingProviders.Count(c => c.Name == vm.Name && c.ID != vm.ID && c.IsDeleted == null); if (checkExist > 0) { return(null); } if (id > 0) //Update { var tr = db.EmployersTrainingProviders .Where(r => r.IsDeleted == null && r.ID == id) .ToList().Single(); tr.Description = vm.Description; tr.Name = vm.Name; tr.Website = vm.Website; tr.LogoPath = string.IsNullOrEmpty(vm.LogoPath)?tr.LogoPath: vm.LogoPath; tr.UpdateUserID = userId; tr.UpdateDate = DateTime.UtcNow; tr.LanguageID = vm.LanguageID; tr.Type = (vm.Type != 0); } else //Insert { var tr = new EmployersTrainingProvider() { Description = vm.Description, Name = vm.Name, Website = vm.Website, LogoPath = vm.LogoPath, PostUserID = userId, PostDate = DateTime.UtcNow, LanguageID = vm.LanguageID, Type = (vm.Type != 0) }; db.EmployersTrainingProviders.Add(tr); db.SaveChanges(); vm.ID = tr.ID; } db.SaveChanges(); } catch (Exception ex) { ExceptionDispatchInfo.Capture(ex).Throw(); } return(vm); } }
public ModelResponse Post(UserInfo user, EmployersTrainingProvidersVM vm) { try { //Authorization if (user == null) { return(new ModelResponse(101)); } var ds = Repo.Post(vm, user.UserId); return(new ModelResponse(0, ds)); } catch (Exception ex) { return(new ModelResponse(ex)); } }
public static object Post(EmployersTrainingProvidersVM vm) { if (vm.ID > 0) { if (Utils.CheckPermission(3, 26, Utils.LoggedUser.Roles) < 1) { return(Utils.ServiceResponse("", new ModelResponse(101), null)); } } else { if (Utils.CheckPermission(2, 26, Utils.LoggedUser.Roles) < 1) { return(Utils.ServiceResponse("", new ModelResponse(101), null)); } } var mr = Mgr.Post(Utils.LoggedUser, vm); return(Utils.ServiceResponse(mr, null)); }