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; } } }
public static IEnumerable <SelectListItem> GetAccountList(string orderState) { var db = new JewelleryDBEntities(); var accounts = AccountBL.GetList(db); var state = (OrderStates)Enum.Parse(typeof(OrderStates), orderState); string role = null; switch (state) { case OrderStates.WAITING: role = Infrastructure.Core.Constants.Roles.Boiler; break; case OrderStates.STONECUTTER: role = Infrastructure.Core.Constants.Roles.StoneCutter; break; case OrderStates.POLISHER: role = Infrastructure.Core.Constants.Roles.Polisher; break; } return(accounts.Where(q => q.Role == role).Select(q => new SelectListItem() { Text = q.FullName, Value = q.Id.ToString() })); }
public static void Delete(int accountId, JewelleryDBEntities db) { var existingAccount = db.Account.Single(q => q.Id == accountId); db.Account.Remove(existingAccount); db.SaveChanges(); }
public static string Login(string mobilePhone, string password, JewelleryDBEntities db) { var account = db.Account.Single(q => q.MobilePhone == mobilePhone && q.Password == password); var tokenString = TokenBL.Create(account.Id, db); return(tokenString); }
public static int Create(AccountDTO account, JewelleryDBEntities db) { var newAccount = AccountMapper.MapToEntity(account); db.Account.Add(newAccount); db.SaveChanges(); return(newAccount.Id); }
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(); }
public static int Create(OrderHistoryDTO orderHistory, JewelleryDBEntities db) { var newOrderHistory = OrderHistoryMapper.MapToEntity(orderHistory); db.OrderHistory.Add(newOrderHistory); db.SaveChanges(); return(newOrderHistory.HID); }
internal static AccountDTO TryGet(int id, JewelleryDBEntities db) { var account = db.Account.SingleOrDefault(q => q.Id == id); if (account == null) { return(null); } return(AccountMapper.MapToDTO(account)); }
public static AccountDTO GetByTokenString(string tokenString, JewelleryDBEntities db) { var token = TokenBL.TryGet(tokenString, db); if (token != null) { var account = db.Account.Single(q => q.Id == token.AccountId); return(AccountMapper.MapToDTO(account)); } return(null); }
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); }
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); }
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); }
public void OnAuthentication(AuthenticationContext filterContext) { if (IsAnonymousAction(filterContext.ActionDescriptor) == true) { return; } FormsAuthenticationTicket ticket = null; try { ticket = AuthenticationHelper.GetTicket(filterContext.HttpContext); } catch (Exception ex) { logger.Debug(ex, "An error occured and supressed while trying to get FormsAuthentication ticket"); filterContext.Result = new HttpUnauthorizedResult(); return; } var userData = AuthenticationHelper.GetUserData(filterContext.HttpContext); AccountDTO account = null; try { var db = new JewelleryDBEntities(); account = AccountBL.GetByTokenString(userData.TokenString, db); } catch (Exception exc) { logger.Debug(exc, "Exception occured and suppressed while checking for authentication by token"); } if (account == null) { filterContext.Result = new HttpUnauthorizedResult(); return; } ticket = AuthenticationHelper.CreateTicket(userData.TokenString, account, ticket?.IsPersistent ?? true); var identity = new FormsIdentity(ticket); filterContext.Principal = new GenericPrincipal(identity, new string[] { account.Role }); }
public static bool IsAccountExists(AccountDTO account, JewelleryDBEntities db) { return(db.Account.Any(q => q.MobilePhone == account.MobilePhone && q.Password == account.Password)); }
public static IEnumerable <AccountDTO> GetList(JewelleryDBEntities db) { return(db.Account.ToList().Select(q => AccountMapper.MapToDTO(q))); }
public static OrderDTO Get(int id, JewelleryDBEntities db) { var order = db.Order.Single(q => q.Id == id); return(OrderMapper.MapToDTO(order)); }
public static void Update(int id, OrderDTO order, JewelleryDBEntities db) { throw new NotImplementedException(); }
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; } } }
public static IEnumerable <OrderDTO> GetList(JewelleryDBEntities db) { return(db.Order.ToList().Select(q => OrderMapper.MapToDTO(q))); }
public static ProductDTO Get(int id, JewelleryDBEntities db) { var product = db.Product.Single(q => q.Id == id); return(ProductMapper.MapToDTO(product)); }
public static IEnumerable <ProductDTO> GetList(JewelleryDBEntities db) { return(db.Product.ToList().Select(q => ProductMapper.MapToDTO(q))); }
public static void Update(int id, ProductDTO product, JewelleryDBEntities db) { throw new NotImplementedException(); }
public static Token TryGet(string tokenString, JewelleryDBEntities db) { return(db.Token.SingleOrDefault(q => q.TokenString == tokenString && q.StartTime <= DateTime.Now && q.EndTime >= DateTime.Now)); }
public static void Delete(int id, JewelleryDBEntities db) { throw new NotImplementedException(); }