public Infrastructure.Data.Entities.HelpfulLinkVm Post(Infrastructure.Data.Entities.HelpfulLinkVm vm, string Userid) { using (var db = new LMISEntities()) { try { var id = vm.HelpfulLinkID; var checkExist = db.HelpfulLinks.Count(c => (c.HelpfulLinkURL == vm.HelpfulLinkURL || c.HelpfulLinkName == vm.HelpfulLinkName) && c.HelpfulLinkLanguage == vm.HelpfulLinkLanguage && c.HelpfulLinkID != vm.HelpfulLinkID && c.IsDeleted == null); if (checkExist > 0) { return(null); } if (id > 0) //Update { var tr = db.HelpfulLinks .Where(r => r.IsDeleted == null && r.HelpfulLinkID == id) .ToList().Single(); tr.HelpfulLinkURL = vm.HelpfulLinkURL; tr.HelpfulLinkName = vm.HelpfulLinkName; tr.HelpfulLinkLanguage = vm.HelpfulLinkLanguage; tr.GroupID = vm.GroupID; tr.UpdateUserID = Userid; tr.UpdateDate = DateTime.UtcNow; } else //Insert { var tr = new HelpfulLink() { HelpfulLinkURL = vm.HelpfulLinkURL, HelpfulLinkName = vm.HelpfulLinkName, HelpfulLinkLanguage = vm.HelpfulLinkLanguage, GroupID = vm.GroupID, PostUserID = Userid, PostDate = DateTime.UtcNow }; db.HelpfulLinks.Add(tr); db.SaveChanges(); vm.HelpfulLinkID = tr.HelpfulLinkID; } db.SaveChanges(); } catch (Exception ex) { ExceptionDispatchInfo.Capture(ex).Throw(); } return(vm); } }
public Infrastructure.Data.DTOs.ModelResponse Post(Infrastructure.Data.DTOs.UserInfo user, Infrastructure.Data.Entities.HelpfulLinkVm vm) { try { //Authorization if (user == null) { return(new ModelResponse(101)); } var ds = Repo.Post(vm, user.UserId); // if(ds==null) // { return new ModelResponse(102, ds); } return(new ModelResponse(0, ds)); } catch (Exception ex) { return(new ModelResponse(ex)); } }