public async Task <Guid> Save(ContactPersonTitleDTO _Dto, Guid Id, int EntityState) { try { ContactPersonTitleMaster _contactPersonTitle = new ContactPersonTitleMaster(); if (_Dto != null) { _contactPersonTitle.Id = Id; _contactPersonTitle.ContactPersonTitle = _Dto.ContactPersonTitle; _contactPersonTitle.Description = _Dto.Description; _contactPersonTitle.ActivatedDate = DateTime.Now; _contactPersonTitle.StatusCode = EMPConstants.Active; } if (EntityState == (int)System.Data.Entity.EntityState.Modified) { _contactPersonTitle.CreatedBy = _Dto.UserId; _contactPersonTitle.CreatedDate = DateTime.Now; _contactPersonTitle.LastUpdatedBy = _Dto.UserId; _contactPersonTitle.LastUpdatedDate = DateTime.Now; db.Entry(_contactPersonTitle).State = System.Data.Entity.EntityState.Modified; } else { _contactPersonTitle.LastUpdatedBy = _Dto.UserId; _contactPersonTitle.LastUpdatedDate = DateTime.Now; db.ContactPersonTitleMasters.Add(_contactPersonTitle); } try { await db.SaveChangesAsync(); return(_contactPersonTitle.Id); } catch (DbUpdateConcurrencyException) { if (!IsExists(_contactPersonTitle.Id)) { return(_contactPersonTitle.Id); } else { return(Guid.Empty); } } } catch (Exception ex) { ExceptionLogger.LogException(ex.ToString(), "ContactPersonTitleMaster/PostContactPersonTitleMaster", Id); return(Guid.Empty); } }
public async Task <Guid> SaveStatus(ContactPersonTitleDTO _Dto, Guid Id, int EntityState) { try { ContactPersonTitleMaster ContactPersonTitle = new ContactPersonTitleMaster(); ContactPersonTitle = await db.ContactPersonTitleMasters.Where(o => o.Id == Id).FirstOrDefaultAsync(); ContactPersonTitle.ActivatedDate = DateTime.Now; if (ContactPersonTitle.StatusCode == EMPConstants.InActive) { ContactPersonTitle.StatusCode = EMPConstants.Active; } else if (ContactPersonTitle.StatusCode == EMPConstants.Active) { ContactPersonTitle.StatusCode = EMPConstants.InActive; } if (EntityState == (int)System.Data.Entity.EntityState.Modified) { ContactPersonTitle.LastUpdatedDate = DateTime.Now; ContactPersonTitle.LastUpdatedBy = _Dto.UserId; db.Entry(ContactPersonTitle).State = System.Data.Entity.EntityState.Modified; } try { await db.SaveChangesAsync(); db.Dispose(); return(ContactPersonTitle.Id); } catch (DbUpdateConcurrencyException) { if (!IsExists(ContactPersonTitle.Id)) { return(Guid.Empty); } else { return(Guid.Empty); } } } catch (Exception ex) { ExceptionLogger.LogException(ex.ToString(), "ContactPersonTitleMaster/PutUserMaster", Id); return(Guid.Empty); } }
public async Task <int> Save(ContactPersonTitleDTO _Dto, Guid Id, int EntityState) { ContactPersonTitleMaster _contactPersonTitle = new ContactPersonTitleMaster(); if (_Dto != null) { _contactPersonTitle.Id = Id; _contactPersonTitle.ContactPersonTitle = _Dto.ContactPersonTitle; _contactPersonTitle.Description = _Dto.Description; _contactPersonTitle.ActivatedDate = DateTime.Now; _contactPersonTitle.StatusCode = EMPConstants.Active; } if (EntityState == (int)System.Data.Entity.EntityState.Modified) { var ExistContact = db.ContactPersonTitleMasters.Where(o => o.Id != Id && o.ContactPersonTitle == _Dto.ContactPersonTitle).Any(); if (ExistContact) { return(-1); } _contactPersonTitle.CreatedBy = _Dto.UserId; _contactPersonTitle.CreatedDate = DateTime.Now; _contactPersonTitle.LastUpdatedBy = _Dto.UserId; _contactPersonTitle.LastUpdatedDate = DateTime.Now; db.Entry(_contactPersonTitle).State = System.Data.Entity.EntityState.Modified; } else { var ExistContact = db.ContactPersonTitleMasters.Where(o => o.ContactPersonTitle == _Dto.ContactPersonTitle).Any(); if (ExistContact) { return(-1); } _contactPersonTitle.LastUpdatedBy = _Dto.UserId; _contactPersonTitle.LastUpdatedDate = DateTime.Now; db.ContactPersonTitleMasters.Add(_contactPersonTitle); } try { await db.SaveChangesAsync(); return(1); } catch (DbUpdateConcurrencyException) { return(0); } }