예제 #1
0
        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"));
        }
예제 #2
0
        public async Task <ActionResult> EditDocumentType(ViewModels.AddDocumentType updateDocumentType)
        {
            if (updateDocumentType != null)
            {
                var currentUser = await db.Users.Where(x => x.UserName == User.Identity.Name)
                                  .SingleOrDefaultAsync();

                if (currentUser != null)
                {
                    var editDocumentType = new Models.DocumentGroup
                    {
                        Permalink = updateDocumentType.IdDocumentType,
                        Title     = updateDocumentType.Name,
                        IsDeleted = false,
                        UpdatedBy = currentUser,
                        Updated   = DateTimeOffset.UtcNow
                    };
                    try
                    {
                        db.Entry(editDocumentType).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"));
        }