Exemple #1
0
        public ProductDTO Add(ProductDTO data, string userName)
        {
            var user = _user.FindUser(userName);

            data.ActionLog = "Create";
            bool isPartner = _partner.IsPartner(data.StoreID, user.ID);

            if (isPartner)
            {
                data.StatusID = WAITINGFORAPPROVE;
            }
            else
            {
                if (_store.IsOwner(data.StoreID, user.ID))
                {
                    data.StatusID = AVAILABLE;
                }
                else
                {
                    return(null);
                }
            }
            data.ProductID    = CodeGenerator.RandomString(6);
            data.CreatedDate  = System.DateTime.Now;
            data.ModifiedDate = System.DateTime.Now;
            ProductDTO product = _repo.Add(data.Translate <ProductDTO, Product>()).Translate <Product, ProductDTO>();

            if (product != null)
            {
                var store = _store.FindByID(data.StoreID);
                store.LimitProduct = store.LimitProduct - 1;
                _store.Edit(store);
                if (isPartner)
                {
                    var mess = new MessageDTO();
                    mess.Description = user.UserName + " created product " + data.Name;
                    mess.FromID      = user.ID;
                    mess.SentID      = store.UserID;
                    mess.DataID      = data.StoreID;
                    mess.MessageType = MESSAGE_PRODUCT;
                    CreateMessage(mess);
                }
            }
            return(product);
        }