Beispiel #1
0
        public OrderStatus CreateOrUpdateOrder(Order order, string updatingUserId)
        {
            int companyId = RetrieveCompanyIdByExtCompanyId(order.ExternalCompanyId);

            //On a update or create we want to make sure a few columns do have data.
            order.Log            = "";
            order.ResultMessage  = "";
            order.ResponseSent   = false;
            order.StartDate      = null;
            order.CompletionDate = null;


            order.Validate(new CustomValidationService(_iOrderRepository, companyId));
            if (order.ValidationErrors.Any())
            {
                string errors = order.ValidationErrors.Aggregate("", (current, error) => current + (error + Environment.NewLine));
                throw new Exception("Order Creation Failed:" + Environment.NewLine + errors);
            }

            var daoOrder = ObjectFactory.CreateInstanceAndMap <Order, DaoOrder>(_iCommonMapper, order);

            daoOrder = _iOrderRepository.CreateOrUpdateOrder(daoOrder, updatingUserId);
            return(ObjectFactory.CreateInstanceAndMap <DaoOrder, OrderStatus>(_iCommonMapper, daoOrder));
        }
Beispiel #2
0
        public OrderStatus UpdateOrder(Order order, string updatingUserId)
        {
            int companyId = RetrieveCompanyIdByExtCompanyId(order.ExternalCompanyId);

            order.Validate(new CustomValidationService(_iOrderRepository, companyId));
            if (order.ValidationErrors.Any())
            {
                string errors = order.ValidationErrors.Aggregate("", (current, error) => current + (error + Environment.NewLine));
                throw new Exception("Update Failed:" + Environment.NewLine + errors);
            }

            //todo: quick fix to set these properties as when a order comes in end user doesn't want to have to set all this.
            //the attach should look for child objects.
            foreach (var service in order.Services)
            {
                service.CreatedByUser  = updatingUserId;
                service.ModifiedByUser = updatingUserId;
                service.DateCreated    = DateTime.Now;
                service.DateModified   = DateTime.Now;
                //service.Version = 0;

                foreach (var location in service.Locations)
                {
                    if (location.InternetItems != null)
                    {
                        foreach (var item in location.InternetItems)
                        {
                            item.CreatedByUser  = updatingUserId;
                            item.ModifiedByUser = updatingUserId;
                            item.DateCreated    = DateTime.Now;
                            item.DateModified   = DateTime.Now;
                            //item.Version = 0;
                        }
                    }

                    if (location.PhoneItems != null)
                    {
                        foreach (var item in location.PhoneItems)
                        {
                            item.CreatedByUser  = updatingUserId;
                            item.ModifiedByUser = updatingUserId;
                            item.DateCreated    = DateTime.Now;
                            item.DateModified   = DateTime.Now;
                            //item.Version = 0;
                        }
                    }

                    if (location.VideoItems != null)
                    {
                        foreach (var item in location.VideoItems)
                        {
                            item.CreatedByUser  = updatingUserId;
                            item.ModifiedByUser = updatingUserId;
                            item.DateCreated    = DateTime.Now;
                            item.DateModified   = DateTime.Now;
                            //item.Version = 0;
                        }
                    }
                }
            }

            var daoOrder = ObjectFactory.CreateInstanceAndMap <Order, DaoOrder>(_iCommonMapper, order);

            daoOrder = _iOrderRepository.UpdateOrder(daoOrder, updatingUserId);
            return(ObjectFactory.CreateInstanceAndMap <DaoOrder, OrderStatus>(_iCommonMapper, daoOrder));
        }