Ejemplo n.º 1
0
        public GeneralResponse AddCenter(IEnumerable <AddCenterRequest> requests, Guid CreateEmployeeID)
        {
            GeneralResponse response = new GeneralResponse();

            try
            {
                foreach (var request in requests)
                {
                    Center center = new Center();
                    center.ID             = Guid.NewGuid();
                    center.CreateDate     = PersianDateTime.Now;
                    center.CreateEmployee = _employeeRepository.FindBy(CreateEmployeeID);
                    center.CenterName     = request.CenterName;
                    center.Note           = request.Note;
                    center.RowVersion     = 1;

                    _centerRepository.Add(center);

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

                        networkCenters.Add(networkCenter);
                    }

                    center.NetworkCenters = networkCenters;

                    #region Validation

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

                        return(response);
                    }

                    #endregion

                    _centerRepository.Add(center);
                }
                _uow.Commit();
            }
            catch (Exception ex)
            {
                response.ErrorMessages.Add(ex.Message);
            }

            return(response);
        }