public async Task <VacancyRequiredDocumentViewModel> Update(long id, VacancyRequiredDocumentViewModel data)
        {
            try
            {
                using (var db = mContext)
                {
                    var obj = await db.tblVacanciesRequiredDocuments.Where(x => x.ID == id).FirstOrDefaultAsync();

                    if (obj != null)
                    {
                        obj.RequiredDocumentName        = data.RequiredDocumentName;
                        obj.RequiredDocumentDescription = data.RequiredDocumentDescription;
                        obj.VacancyID        = data.VacancyID;
                        obj.IsMandatory      = data.IsMandatory;
                        obj.IsActive         = data.isActive;
                        obj.UpdatedTimestamp = DateTime.UtcNow;
                        obj.UpdatedUserID    = data.updatedUserID;
                    }
                    else
                    {
                        new Exception("Update Failed. Please verify data");
                    }
                    await db.SaveChangesAsync();

                    return(new VacancyRequiredDocumentViewModel
                    {
                        ID = obj.ID,
                        RequiredDocumentName = obj.RequiredDocumentName,
                        RequiredDocumentDescription = obj.RequiredDocumentDescription,
                        VacancyID = obj.VacancyID,
                        IsMandatory = obj.IsMandatory,
                        isActive = obj.IsActive,
                        isDeleted = obj.IsDeleted,
                        createdTimestamp = obj.CreatedTimestamp
                    });
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public async Task <VacancyRequiredDocumentViewModel> Save(VacancyRequiredDocumentViewModel data)
        {
            try
            {
                using (var db = mContext)
                {
                    var obj = new tblVacanciesRequiredDocument()
                    {
                        RequiredDocumentName        = data.RequiredDocumentName,
                        RequiredDocumentDescription = data.RequiredDocumentDescription,
                        VacancyID        = data.VacancyID,
                        IsActive         = data.isActive,
                        IsMandatory      = data.IsMandatory,
                        IsDeleted        = data.isDeleted,
                        CreatedTimestamp = DateTime.UtcNow,
                        CreatedUserID    = data.createdUserID
                    };

                    db.tblVacanciesRequiredDocuments.Add(obj);
                    await db.SaveChangesAsync();

                    return(new VacancyRequiredDocumentViewModel
                    {
                        ID = obj.ID,
                        RequiredDocumentName = obj.RequiredDocumentName,
                        RequiredDocumentDescription = obj.RequiredDocumentDescription,
                        VacancyID = obj.VacancyID,
                        IsMandatory = obj.IsMandatory,
                        isActive = obj.IsActive,
                        isDeleted = obj.IsDeleted,
                        createdTimestamp = obj.CreatedTimestamp
                    });
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 3
0
 public static tblVacanciesRequiredDocument ConvertTotblVacanciesRequiredDocument(this VacancyRequiredDocumentViewModel data)
 {
     return(new tblVacanciesRequiredDocument()
     {
         ID = Convert.ToInt16(data.ID),
         RequiredDocumentName = data.RequiredDocumentName,
         RequiredDocumentDescription = data.RequiredDocumentDescription,
         RequiredDocumentID = data.RequiredDocumentID,
         IsMandatory = data.IsMandatory,
         VacancyID = data.VacancyID,
         IsActive = data.isActive,
         IsDeleted = data.isDeleted ?? false,
         CreatedUserID = data.createdUserID,
         UpdatedUserID = data.updatedUserID,
         CreatedTimestamp = data.createdTimestamp ?? DateTime.Now,
         UpdatedTimestamp = data.updatedTimestamp ?? DateTime.Now
     });
 }