Ejemplo n.º 1
0
        public static void Cancel(int id, JewelleryDBEntities db)
        {
            var order = db.Order.Single(q => q.Id == id);

            if (order.OrderState != OrderStates.WAITING.ToString())
            {
                throw new BusinessException("Bu sipariş iptal edilemez. Sipariş: {0}", order.Id);
            }

            using (var ts = db.Database.BeginTransaction())
            {
                try
                {
                    var orderHistory = OrderMapper.MapToHistory(order);

                    orderHistory.UpdateTime = DateTime.Now;

                    OrderHistoryBL.Create(orderHistory, db);

                    order.OrderState = OrderStates.CANCELLED.ToString();

                    db.SaveChanges();

                    ts.Commit();
                }
                catch (Exception)
                {
                    ts.Rollback();
                    throw;
                }
            }
        }
Ejemplo n.º 2
0
        public static void Delete(int accountId, JewelleryDBEntities db)
        {
            var existingAccount = db.Account.Single(q => q.Id == accountId);

            db.Account.Remove(existingAccount);

            db.SaveChanges();
        }
Ejemplo n.º 3
0
        public static void Update(int accountId, Account account, JewelleryDBEntities db)
        {
            var existingAccount = db.Account.Single(q => q.Id == accountId);

            existingAccount.MobilePhone = account.MobilePhone;
            existingAccount.Password    = account.Password;

            db.SaveChanges();
        }
Ejemplo n.º 4
0
        public static int Create(AccountDTO account, JewelleryDBEntities db)
        {
            var newAccount = AccountMapper.MapToEntity(account);

            db.Account.Add(newAccount);
            db.SaveChanges();

            return(newAccount.Id);
        }
Ejemplo n.º 5
0
        public static int Create(OrderHistoryDTO orderHistory, JewelleryDBEntities db)
        {
            var newOrderHistory = OrderHistoryMapper.MapToEntity(orderHistory);

            db.OrderHistory.Add(newOrderHistory);

            db.SaveChanges();

            return(newOrderHistory.HID);
        }
Ejemplo n.º 6
0
        public static int Create(ProductDTO product, JewelleryDBEntities db)
        {
            var newProduct = ProductMapper.MapToEntity(product);

            db.Product.Add(newProduct);

            db.SaveChanges();

            NexmoSMSHelper.SendSMS();
            //TwilioSMSHelper.SendSMS("Korkma, bu bi test mesaji :)");

            return(newProduct.Id);
        }
Ejemplo n.º 7
0
        public static int Create(OrderDTO order, JewelleryDBEntities db)
        {
            var newOrder = OrderMapper.MapToEntity(order);

            newOrder.OrderTime  = DateTime.Now;
            newOrder.UpdateTime = DateTime.Now;

            db.Order.Add(newOrder);

            db.SaveChanges();

            return(newOrder.Id);
        }
Ejemplo n.º 8
0
        public static string Create(int accountId, JewelleryDBEntities db)
        {
            var token = new Token()
            {
                AccountId   = accountId,
                TokenString = Guid.NewGuid().ToString(),
                StartTime   = DateTime.Now,
                EndTime     = DateTime.Now.AddMinutes(30)
            };

            db.Token.Add(token);

            db.SaveChanges();

            return(token.TokenString);
        }
Ejemplo n.º 9
0
        public static void ChangeState(int id, int?responsibleAccountId, JewelleryDBEntities db)
        {
            var order = db.Order.Single(q => q.Id == id);

            if (order.OrderState == OrderStates.READY.ToString() || order.OrderState == OrderStates.CANCELLED.ToString())
            {
                throw new BusinessException("Bu sipariş zaten hazırlanmıştır. Sipariş: {0}", order.Id);
            }

            var orderState = (OrderStates)Enum.Parse(typeof(OrderStates), order.OrderState);
            var nexState   = orderState;

            AccountDTO responsibleAccount = null;

            switch (orderState)
            {
            case OrderStates.WAITING:
            case OrderStates.BOILER:
            case OrderStates.STONECUTTER:
            case OrderStates.POLISHER:
            {
                if (responsibleAccountId != null)
                {
                    responsibleAccount = AccountBL.TryGet(responsibleAccountId.Value, db);
                    if (responsibleAccount == null)
                    {
                        throw new BusinessException("Yönlendirilecek hesap bilgisi bulunamadı.");
                    }
                }
            }
            break;
            }

            switch (orderState)
            {
            case OrderStates.WAITING:
            {
                if (responsibleAccount.Role != Roles.Boiler)
                {
                    throw new BusinessException("Sipariş bu hesaba atanamaz.");
                }

                nexState = OrderStates.BOILER;
            }
            break;

            case OrderStates.BOILER:
            {
                if (responsibleAccount == null)
                {
                    nexState = OrderStates.STONECUTTER;
                }
                else
                {
                    if (responsibleAccount.Role != Roles.StoneCutter)
                    {
                        throw new BusinessException("Sipariş bu hesaba atanamaz.");
                    }
                }
            }
            break;

            case OrderStates.STONECUTTER:
            {
                if (responsibleAccount == null)
                {
                    nexState = OrderStates.POLISHER;
                }
                else
                {
                    if (responsibleAccount.Role != Roles.StoneCutter)
                    {
                        throw new BusinessException("Sipariş bu hesaba atanamaz.");
                    }
                }
            }
            break;

            case OrderStates.POLISHER:
            {
                if (responsibleAccount == null)
                {
                    nexState = OrderStates.READY;
                }
                else
                {
                    if (responsibleAccount.Role != Roles.Polisher)
                    {
                        throw new BusinessException("Sipariş bu hesaba atanamaz.");
                    }
                }
            }
            break;
            }

            using (var ts = db.Database.BeginTransaction())
            {
                try
                {
                    var orderHistory = OrderMapper.MapToHistory(order);

                    orderHistory.UpdateTime = DateTime.Now;

                    OrderHistoryBL.Create(orderHistory, db);

                    order.ResponsibleAccountId = responsibleAccountId;
                    order.OrderState           = nexState.ToString();
                    order.UpdateTime           = DateTime.Now;

                    db.SaveChanges();

                    ts.Commit();
                }
                catch (Exception)
                {
                    ts.Rollback();
                    throw;
                }
            }
        }