public async Task <IHttpActionResult> Update(RequiredDocumentViewModel model) { try { userId = User.Identity.GetUserId(); Helpers.Helpers.AddBaseProperties(model, "update", userId); return(Ok(await Service.Update(model.ID, model))); } catch (Exception) { throw; } }
public async Task <RequiredDocumentViewModel> Update(long id, RequiredDocumentViewModel data) { try { using (var db = mContext) { var obj = await db.tblMSPRequiredDocuments.Where(x => x.ID == id).FirstOrDefaultAsync(); if (obj != null) { obj.RequiredDocumentName = data.RequiredDocumentName; obj.RequiredDocumentDescription = data.RequiredDocumentDescription; obj.IsDefault = data.IsDefault; obj.IsMandatory = data.IsMandatory; obj.IsActive = data.isActive; obj.UpdatedTimestamp = DateTime.UtcNow; obj.UpdatedUserID = data.updatedUserID; obj.IsDeleted = data.isDeleted; } else { new Exception("Update Failed. Please verify data"); } await db.SaveChangesAsync(); return(new RequiredDocumentViewModel { ID = obj.ID, RequiredDocumentName = obj.RequiredDocumentName, RequiredDocumentDescription = obj.RequiredDocumentDescription, IsDefault = obj.IsDefault, IsMandatory = obj.IsMandatory, isActive = obj.IsActive, isDeleted = obj.IsDeleted, createdTimestamp = obj.CreatedTimestamp }); } } catch (Exception) { throw; } }
public async Task <RequiredDocumentViewModel> Save(RequiredDocumentViewModel data) { try { using (var db = mContext) { var obj = new tblMSPRequiredDocument() { RequiredDocumentName = data.RequiredDocumentName, RequiredDocumentDescription = data.RequiredDocumentDescription, IsDefault = data.IsDefault, IsActive = data.isActive, IsMandatory = data.IsMandatory, IsDeleted = data.isDeleted, CreatedTimestamp = DateTime.UtcNow, CreatedUserID = data.createdUserID }; db.tblMSPRequiredDocuments.Add(obj); await db.SaveChangesAsync(); return(new RequiredDocumentViewModel { ID = obj.ID, RequiredDocumentName = obj.RequiredDocumentName, RequiredDocumentDescription = obj.RequiredDocumentDescription, IsDefault = obj.IsDefault, IsMandatory = obj.IsMandatory, isActive = obj.IsActive, isDeleted = obj.IsDeleted, createdTimestamp = obj.CreatedTimestamp, IsSelected = false }); } } catch (Exception) { throw; } }