public void Delete(int id)
 {
     using (UoW)
     {
         var error = UoW.Errors.Get(id);
         if (error == null)
         {
             throw new ApplicationOperationException(string.Format("Error with id {0} not found", id), HttpStatusCode.NotFound);
         }
         if (error.Solution != null)
         {
             if (error.Solution.Attachments.Count > 0)
             {
                 foreach (var attachment in error.Solution.Attachments)
                 {
                     System.IO.File.Delete(Path.Combine(_solutionAttachService.root, attachment.FileName));
                 }
                 UoW.SolutionAttachments.RemoveRange(error.Solution.Attachments);
             }
             UoW.Solutions.Remove(error.Solution);
         }
         if (error.Attachments.Count > 0)
         {
             foreach (var attachment in error.Attachments)
             {
                 System.IO.File.Delete(Path.Combine(_errorAttachService.root, attachment.FileName));
             }
             UoW.ErrorAttachments.RemoveRange(error.Attachments);
         }
         UoW.Errors.Remove(error);
         UoW.Complete();
     }
 }
 public AssigneeUpdateDTO UpdateAssignee(int id, AssigneeUpdateDTO assignee)
 {
     using (UoW)
     {
         var error = UoW.Errors.Get(id);
         if (error == null)
         {
             throw new ApplicationOperationException(string.Format("Error with id {0} not found", id), HttpStatusCode.NotFound);
         }
         if (assignee.EmailAssignee != null)
         {
             var newAssignee = UoW.Users.GetByEmail(assignee.EmailAssignee);
             if (newAssignee == null)
             {
                 throw new ApplicationOperationException(string.Format("Error assignee with email {0} not found", assignee.EmailAssignee), HttpStatusCode.NotFound);
             }
             error.Assignee = newAssignee;
         }
         if (assignee.EmailAssignee == null)
         {
             error.AssigneeId = null;
             error.Assignee   = null;
         }
         UoW.Complete();
         return(assignee);
     }
 }
 public ErrorDTO Add(int projectId, ErrorDTO errorDto)
 {
     using (UoW)
     {
         var error   = Mapper.Map <Error>(errorDto);
         var project = UoW.Projects.Get(projectId);
         if (project == null)
         {
             throw new ApplicationOperationException(string.Format("Project with id {0} not found", projectId), HttpStatusCode.NotFound);
         }
         if (errorDto.EmailAssignee != null)
         {
             var assignee = UoW.Users.GetByEmail(errorDto.EmailAssignee);
             if (assignee == null)
             {
                 throw new ApplicationOperationException(string.Format("Error assignee with email {0} not found", errorDto.EmailAssignee), HttpStatusCode.NotFound);
             }
             error.Assignee = assignee;
         }
         else
         {
             error.Assignee = null;
         }
         error.Project = project;
         error.Author  = CurrentUser;
         UoW.Errors.Add(error);
         UoW.Complete();
         return(Mapper.Map <ErrorDTO>(error));
     }
 }
Ejemplo n.º 4
0
        public PortalDTO Create(PortalDTO portalDto)
        {
            using (UoW)
            {
                AppUser userExists = UoW.Users.GetByEmail(portalDto.Owner.Email);
                if (userExists != null)
                {
                    throw new ApplicationOperationException(string.Format("User with email {0} already exists", portalDto.Owner.Email), HttpStatusCode.Conflict);
                }

                if (UoW.Portals.Find(prl => prl.Title == portalDto.Title).Count <Portal>() > 0)
                {
                    throw new ApplicationOperationException(string.Format("Portal with name {0} already exists", portalDto.Title), HttpStatusCode.Conflict);
                }

                //AppUser user = Mapper.Map<AppUser>(portalDto.Owner);
                var user = new AppUser()
                {
                    Email = portalDto.Owner.Email, UserName = portalDto.Owner.Email
                };

                UoW.Users.Add(user, portalDto.Owner.Password, portalDto.Owner.RoleName);
                Portal portal = new Portal()
                {
                    Id = user.Id, Title = portalDto.Title
                };
                UoW.Portals.Add(portal);
                UoW.Complete();
                return(Mapper.Map <PortalDTO>(portal));
            }
        }
Ejemplo n.º 5
0
 public string ConfirmAttachmentUser(ConfirmAttachmentUserDTO confirmUserDto)
 {
     using (UoW)
     {
         Guid   id;
         string portalName = "";
         if (!Guid.TryParse(confirmUserDto.guid, out id))
         {
             throw new ApplicationOperationException(string.Format("Guid {0} is invalid", confirmUserDto.guid), HttpStatusCode.BadRequest);
         }
         var awaitAttach = UoW.AwaitingAttachmentUsers.Get(id);
         if (awaitAttach == null)
         {
             throw new ApplicationOperationException(string.Format("AwaitingAttachmentUser row with guid {0} not found", confirmUserDto.guid), HttpStatusCode.NotFound);
         }
         var attachUser = new AttachUserDTO()
         {
             Email = awaitAttach.Email, RoleName = awaitAttach.Role.Name, ProjectId = awaitAttach.ProjectId
         };
         var user = new AppUser()
         {
             Email = attachUser.Email, UserName = attachUser.Email
         };
         UoW.Users.Add(user, confirmUserDto.Password, attachUser.RoleName);
         //portalName = user.Portal.Title;
         UoW.Complete();
         AttachUserToProject(attachUser);
         UoW.AwaitingAttachmentUsers.Remove(awaitAttach);
         UoW.Complete();
         return(portalName);
     }
 }
Ejemplo n.º 6
0
        public async Task <ActionResult> Update(Purchase purchase)
        {
            UoW.Purchases.Update(purchase);
            await UoW.Complete();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 7
0
 public void UnattachUser(UnattachUserDTO unattachUserDto)
 {
     using (UoW)
     {
         Project project = UoW.Projects.Get(unattachUserDto.ProjectId);
         if (project == null)
         {
             throw new ApplicationOperationException(string.Format("Project with id {0} not found", unattachUserDto.ProjectId), HttpStatusCode.NotFound);
         }
         AppUser user = UoW.Users.GetByEmail(unattachUserDto.Email);
         if (user == null)
         {
             throw new ApplicationOperationException(string.Format("User with email {0} not found", unattachUserDto.Email), HttpStatusCode.NotFound);
         }
         var userProject = UoW.UserProjects.Find(up => up.ProjectId == project.Id && up.WorkerId == user.Id).FirstOrDefault();
         if (userProject == null)
         {
             throw new ApplicationOperationException(string.Format("User with email {0} not attached to project {1}", unattachUserDto.Email, project.Title), HttpStatusCode.NotFound);
         }
         UoW.UserProjects.Remove(userProject);
         var errors = project.Errors.Where(e => e.AuthorId == user.Id);
         foreach (var error in errors)
         {
             error.Assignee   = null;
             error.AssigneeId = null;
         }
         UoW.Complete();
     }
 }
        public async Task <ActionResult> Update(Branch branch)
        {
            UoW.Branches.Update(branch);
            await UoW.Complete();

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Update(Customer customer)
        {
            UoW.Customers.Update(customer);
            await UoW.Complete();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 10
0
        public async Task <ActionResult> AddOrEditProduct(Product product)
        {
            if (product.ImageUpload != null)
            {
                string fileName      = Path.GetFileNameWithoutExtension(product.ImageUpload.FileName);
                string ext           = Path.GetExtension(product.ImageUpload.FileName);
                string swap_fileName = fileName;
                fileName          = product.Name.Trim();
                fileName          = fileName + DateTime.Now.ToString("yymmssfff") + ext;
                product.ImagePath = "~/AppFiles/ProductImages/" + fileName;
                product.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/AppFiles/ProductImages/"), fileName));
            }

            if (product.ProdID != 0)
            {
                UoW.Products.Update(product);
            }
            else
            {
                UoW.Products.Add(product);
            }
            await UoW.Complete();

            return(RedirectToAction("ViewProducts"));
        }
        public async Task <ActionResult> Update(Production production)
        {
            UoW.Productions.Update(production);
            await UoW.Complete();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 12
0
 public ErrorSolutionDTO Add(int errorId, ErrorSolutionDTO sln)
 {
     using (UoW)
     {
         var error = UoW.Errors.Get(errorId);
         if (error == null)
         {
             throw new ApplicationOperationException(string.Format("Error with id {0} not found", errorId), HttpStatusCode.NotFound);
         }
         if (error.Solution != null)
         {
             Delete(error.Solution.Id);
         }
         error.Status = sln.ErrorStatus;
         var solution = new ErrorSolution()
         {
             Error         = error,
             Description   = sln.Description,
             RecievingDate = DateTime.UtcNow,
             Author        = CurrentUser
         };
         UoW.Solutions.Add(solution);
         UoW.Complete();
         return(Mapper.Map <ErrorSolutionDTO>(solution));
     }
 }
        public async Task <ActionResult> Update(Division division)
        {
            UoW.Divisions.Update(division);
            await UoW.Complete();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 14
0
        public async Task <ActionResult> DeleteProduct(int id)
        {
            Product product = await UoW.Products.GetAsync(id);

            UoW.Products.Remove(product);
            await UoW.Complete();

            return(RedirectToAction("ViewProducts"));
        }
Ejemplo n.º 15
0
        public async Task <ActionResult> Delete(int id)
        {
            var location = await UoW.Locations.GetAsync(id);

            UoW.Locations.Remove(location);
            await UoW.Complete();

            return(RedirectToAction("ViewLocations"));
        }
Ejemplo n.º 16
0
        public async Task <ActionResult> Delete(int id)
        {
            Category category = await UoW.Categories.GetAsync(id);

            UoW.Categories.Remove(category);
            await UoW.Complete();

            return(RedirectToAction("ViewCategories"));
        }
Ejemplo n.º 17
0
        public async Task <ActionResult> DeleteMany(IEnumerable <Purchase> purchases)
        {
            if (purchases != null)
            {
                UoW.Purchases.RemoveRange(purchases);
                await UoW.Complete();
            }

            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> DeleteMany(IEnumerable <Production> productions)
        {
            if (productions != null)
            {
                UoW.Productions.RemoveRange(productions);
                await UoW.Complete();
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 19
0
        public async Task <ActionResult> DeleteMany(IEnumerable <InventoryItem> stocks)
        {
            if (stocks != null)
            {
                UoW.Stocks.RemoveRange(stocks);
                await UoW.Complete();
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 20
0
        public async Task<ActionResult> DeleteMany(IEnumerable<SalesInvoice> invoices)
        {
            if (invoices != null)
            {
                UoW.SalesInvoices.RemoveRange(invoices);
                await UoW.Complete();
            }

            return RedirectToAction("Index");
        }
Ejemplo n.º 21
0
        public async Task <ActionResult> DeleteMany(IEnumerable <Supplier> suppliers)
        {
            if (suppliers != null)
            {
                UoW.Suppliers.RemoveRange(suppliers);
                await UoW.Complete();
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 22
0
        public async Task <ActionResult> Delete(int id)
        {
            var group = await UoW.Groups.GetAsync(id);

            if (group != null)
            {
                UoW.Groups.Remove(group);
                await UoW.Complete();
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 23
0
 public UserDTO UpdateAttachedUser(AttachUserDTO updateUserDto)
 {
     using (UoW)
     {
         var user        = UoW.Users.GetByEmail(updateUserDto.Email);
         var role        = UoW.Roles.GetByName(updateUserDto.RoleName);
         var userProject = UoW.UserProjects.Find(up => up.ProjectId == updateUserDto.ProjectId && up.WorkerId == user.Id).FirstOrDefault();
         userProject.Role = role;
         UoW.Complete();
         return(Mapper.Map <UserDTO>(userProject));
     }
 }
Ejemplo n.º 24
0
 public async Task<ActionResult> Delete(int id)
 {
     var invoice = await UoW.SalesInvoices.GetAsync(id);
     if (invoice != null)
     {
         var items = await UoW.Ingredients.GetItems(id);
         UoW.SalesInvoices.Remove(invoice);
         UoW.Ingredients.RemoveRange(items);
         await UoW.Complete();
     }
     return RedirectToAction("Index");
 }
Ejemplo n.º 25
0
        public async Task <ActionResult> Delete(int id)
        {
            var stock = await UoW.Stocks.GetAsync(id);

            if (stock != null)
            {
                UoW.Stocks.Remove(stock);
                await UoW.Complete();

                // return RedirectToAction("Index");
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 26
0
        public async Task <ActionResult> DeleteSupplier(int id)
        {
            var supplier = await UoW.Suppliers.GetAsync(id);

            if (supplier != null)
            {
                UoW.Suppliers.Remove(supplier);
                await UoW.Complete();

                // return RedirectToAction("Index");
            }
            return(RedirectToAction("Index"));
        }
        public async Task <ActionResult> Delete(int id)
        {
            var branch = await UoW.Branches.GetAsync(id);

            if (branch != null)
            {
                UoW.Branches.Remove(branch);
                await UoW.Complete();

                // return RedirectToAction("Index");
            }
            return(RedirectToAction("Index"));
        }
 public void Delete(int id)
 {
     using (UoW)
     {
         Project project = UoW.Projects.Get(id);
         if (project == null)
         {
             throw new ApplicationOperationException(string.Format("Project with id {0} not found", id), HttpStatusCode.NotFound);
         }
         UoW.Projects.Remove(project);
         UoW.Complete();
     }
 }
Ejemplo n.º 29
0
        public async Task <ActionResult> AddMultiple(IEnumerable <Supplier> suppliers)
        {
            if (suppliers != null)
            {
                UoW.Suppliers.AddRange(suppliers);
                await UoW.Complete();

                return(RedirectToAction("Index"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }
        }
        public async Task <ActionResult> Create(Branch branch)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            else
            {
                UoW.Branches.Add(branch);
                await UoW.Complete();

                return(RedirectToAction("Index"));
            }
        }