public async Task <ActionResult> DeleteDocumentType(ViewModels.EditDocumentType updateDocumentType)
        {
            if (updateDocumentType != null)
            {
                var currentUser = await db.Users.Where(x => x.UserName == User.Identity.Name)
                                  .SingleOrDefaultAsync();

                if (currentUser != null)
                {
                    var documentType = new Models.DocumentGroup
                    {
                        IsDeleted = true,
                        DeletedBy = currentUser,
                        Deleted   = DateTimeOffset.UtcNow
                    };
                    try
                    {
                        db.Entry(documentType).State = EntityState.Modified;
                        var result = await db.SaveChangesAsync();

                        if (result > 0)
                        {
                            return(RedirectToAction("DocumentType", "VillageHead"));
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError(ex.Message);
                        Trace.TraceError(ex.StackTrace);
                    }
                }
            }
            return(View("Error"));
        }
 /// <summary>
 ///  Create domain model from web model
 /// </summary>
 public static DocumentGroup CreateFrom(this Models.DocumentGroup source)
 {
     return(new DocumentGroup
     {
         DocumentGroupId = source.DocumentGroupId,
         DocumentGroupCode = source.DocumentGroupCode,
         DocumentGroupName = source.DocumentGroupName,
         DocumentGroupDescription = source.DocumentGroupDescription
     });
 }
        public async Task <ActionResult> AddDocumentType(ViewModels.AddDocumentType newDocumentType)
        {
            if (ModelState.IsValid)
            {
                var currentUser = await db.Users.Where(x => x.UserName == User.Identity.Name)
                                  .SingleOrDefaultAsync();

                var fileDocument = await db.FileDocuments.Where(x => x.IdFileDocument == newDocumentType.FileDocument).SingleOrDefaultAsync();

                if (currentUser != null)
                {
                    var addDocumentType = new Models.DocumentGroup
                    {
                        Permalink     = newDocumentType.IdDocumentType,
                        Title         = newDocumentType.Name,
                        FileDocuments = fileDocument,
                        Order         = newDocumentType.Order,
                        IsDeleted     = false,
                        CreatedBy     = currentUser,
                        Created       = DateTimeOffset.UtcNow
                    };
                    try
                    {
                        db.DocumentTypes.Add(addDocumentType);
                        var result = await db.SaveChangesAsync();

                        if (result > 0)
                        {
                            return(RedirectToAction("DocumentType", "VillageHead"));
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError(ex.Message);
                        Trace.TraceError(ex.StackTrace);
                    }
                }
            }
            return(View("Error"));
        }