public void PerformOperation(OperationModel operation)
 {
     MembershipUser mu = Membership.GetUser();
     Guid userId = (Guid)mu.ProviderUserKey;
     operation.OperationId = Convert.ToInt32(operation.OperationId);
     this.UpdateProductAfterOperation(operation);
     SourseDbFactory.GetSourseDB().AddNewOperation(operation, userId, DateTime.Now);
 }
 public void AddNewOperation(OperationModel operation, Guid userId, DateTime dateOperation)
 {
     using (var db = GetDbConnection())
     {
         StatisticsOperation newOperation = new StatisticsOperation();
         newOperation.OperationTypeId = operation.OperationId;
         newOperation.ProductId = operation.ProductId;
         newOperation.Quantity = operation.Quantity;
         newOperation.UserId = userId;
         newOperation.DateOperation = dateOperation;
         db.StatisticsOperation.Add(newOperation);
         db.SaveChanges();
     }
 }
 public JsonResult CreateProductOperation(OperationModel operation)
 {
     try
     {
         if (ModelState.IsValid)
         {
             OperationManager operationManager = new OperationManager();
             operationManager.PerformOperation(operation);
         }
     }
     catch (Exception e)
     {
         LogSystem.Instance.PublishErrorMassage(ErrorDictionary.MASSAGE_UNNOUN_ERROR);
     }
     return PrepareJsonResult();
 }
        private void UpdateProductAfterOperation(OperationModel operation)
        {
            ProductModel product = SourseDbFactory.GetSourseDB().GetProductById(operation.ProductId);

            if (operation.OperationId == GetOperationId("arrival"))
            {
                product.Quantity = product.Quantity + operation.Quantity;
            }

            if (operation.OperationId == GetOperationId("expense"))
            {
                product.Quantity = product.Quantity - operation.Quantity;
            }

            SourseDbFactory.GetSourseDB().UpdateProduct(product);
        }
        public OperationModel CreateNewOperation(int id)
        {
            OperationModel newOperation = new OperationModel();
            newOperation.ProductId = id;
            ProductManager productMamager = new ProductManager();
            newOperation.ProductName = productMamager.GetProduct(id).Name;
            List<SelectListItem> list = new List<SelectListItem>();

            foreach(var operation in _DbOperationType)
            {
                list.Add(new SelectListItem
                {
                    Value = operation.Value.ToString(),
                    Text = operation.Key,
                });
            }
            newOperation.ListTypeOperation = new SelectList(list, "Value", "Text");
            return newOperation;
        }