Esempio n. 1
0
        public ActionResult Create(NetworkDetailView networkDetailView)
        {
            networkDetailView.EmployeeView = GetEmployee();

            #region Access Check
            bool hasPermission = GetEmployee().IsGuaranteed("Network_Insert");
            if (!hasPermission)
            {
                ModelState.AddModelError("", "AccessDenied");
                return(View(networkDetailView));
            }
            #endregion

            if (ModelState.IsValid)
            {
                try
                {
                    AddNetworkRequestOld request = new AddNetworkRequestOld();
                    request.CreateEmployeeID     = GetEmployee().ID;
                    request.DeliverWhenCreditLow = networkDetailView.NetworkView.DeliverWhenCreditLow;
                    request.NetworkName          = networkDetailView.NetworkView.NetworkName;
                    request.Note = networkDetailView.NetworkView.Note;

                    GeneralResponse response = this._networkService.AddNetwork(request);

                    if (response.success)
                    {
                        return(RedirectToAction("Index"));
                    }
                    else
                    {
                        foreach (string error in response.ErrorMessages)
                        {
                            ModelState.AddModelError("", error);
                        }
                        return(View(networkDetailView));
                    }
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", ex.Message);
                    return(View(networkDetailView));
                }
            }

            return(View(networkDetailView));
        }
Esempio n. 2
0
        public GeneralResponse AddNetwork(AddNetworkRequestOld request)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                Network network = new Network();
                network.ID                   = Guid.NewGuid();
                network.CreateDate           = PersianDateTime.Now;
                network.CreateEmployee       = _employeeRepository.FindBy(request.CreateEmployeeID);
                network.DeliverWhenCreditLow = request.DeliverWhenCreditLow;
                network.NetworkName          = request.NetworkName;
                network.Note                 = request.Note;

                network.RowVersion = 1;

                // Validation
                if (network.GetBrokenRules().Count() > 0)
                {
                    foreach (BusinessRule businessRule in network.GetBrokenRules())
                    {
                        response.ErrorMessages.Add(businessRule.Rule);
                    }

                    return(response);
                }

                // be jaye Triggere After Insert. NetworkCenter-ha insert mishavad
                IList <NetworkCenter> networkCenters = new List <NetworkCenter>();
                foreach (Center center in _centerRepository.FindAll())
                {
                    NetworkCenter networkCenter = new NetworkCenter();
                    networkCenter.Network        = network;
                    networkCenter.Center         = center;
                    networkCenter.CreateDate     = PersianDateTime.Now;
                    networkCenter.CreateEmployee = network.CreateEmployee;
                    networkCenter.Status         = NetworkCenterStatus.NotDefined;
                    networkCenter.RowVersion     = 1;

                    networkCenters.Add(networkCenter);
                }

                network.NetworkCenters = networkCenters;
                _networkRepository.Add(network);

                _uow.Commit();

                ////response.success = true;
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
                if (ex.InnerException != null)
                {
                    response.ErrorMessages.Add("FIRST INNER EXPCEPTION: " + ex.InnerException.Message);
                    if (ex.InnerException.InnerException != null)
                    {
                        response.ErrorMessages.Add("SECOND INNER EXPCEPTION: " + ex.InnerException.InnerException.Message);
                    }
                }
            }

            return(response);
        }