public OperationResult DeleteUserFunc(long userFuncId)
        {
            try
            {
                var dbContext = new AlohaDb();

                var func = dbContext.UserFuncs.First(f => f.Id == userFuncId);

                dbContext.UserFuncs.Remove(func);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = func.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
        public OperationResultValue <ServiceDataContracts.UserFunc> GetUserFunc(long userFuncId)
        {
            try
            {
                var dbContext = new AlohaDb();

                var result = dbContext.UserFuncs.First(uf => uf.Id == userFuncId);

                var userFunc = new ServiceDataContracts.UserFunc()
                {
                    Id   = result.Id,
                    Name = result.Name
                };

                return(new OperationResultValue <ServiceDataContracts.UserFunc>
                {
                    Success = true,
                    Result = userFunc
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResultValue <ServiceDataContracts.UserFunc>
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
        public OperationResult UpdateUserFunc(ServiceDataContracts.UserFunc userFunc)
        {
            try
            {
                var dbContext = new AlohaDb();

                var func = dbContext.UserFuncs.First(uf => uf.Id == userFunc.Id);

                func.Name = userFunc.Name;
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = func.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
Esempio n. 4
0
        public OperationResultValue <List <ServiceDataContracts.ContactPerson> > GetContactPersonList()
        {
            try
            {
                var dbContext = new AlohaDb();

                var result = dbContext.ContactPersons.Select(cp => new ServiceDataContracts.ContactPerson
                {
                    Id         = cp.Id,
                    FirstName  = cp.FirstName,
                    SecondName = cp.SecondName,
                    Phone      = cp.Phone,
                    IsActive   = cp.IsActive,
                    Email      = cp.Email
                }).ToList();
                return(new OperationResultValue <List <ServiceDataContracts.ContactPerson> >
                {
                    Success = true,
                    Result = result
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResultValue <List <ServiceDataContracts.ContactPerson> >
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
Esempio n. 5
0
        public OperationResult CreateContactPerson(ServiceDataContracts.ContactPerson contactPerson)
        {
            try
            {
                var dbContext = new AlohaDb();

                var cp = new Entities.ContactPerson();
                cp.FirstName  = contactPerson.FirstName;
                cp.SecondName = contactPerson.SecondName;
                cp.Phone      = contactPerson.Phone;
                cp.IsActive   = contactPerson.IsActive;
                cp.Email      = contactPerson.Email;

                dbContext.ContactPersons.Add(cp);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = cp.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
        public OperationResult CreateMarketingChannel(ServiceDataContracts.MarketingChannel MarketingChannel)
        {
            try
            {
                var dbContext = new AlohaDb();

                var dp = new Entities.MarketingChannel();
                dp.Name = MarketingChannel.Name;

                dp.IsActive = MarketingChannel.IsActive;
                dbContext.MarketingChannel.Add(dp);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = dp.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
        public OperationResult CreateUserGroup(ServiceDataContracts.UserGroup userGroup)
        {
            try
            {
                var dbContext = new AlohaDb();

                var group = new Entities.UserGroup();
                group.Name = userGroup.Name;

                dbContext.UserGroups.Add(group);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = group.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
        public OperationResult DeleteUserGroup(long userGroupId)
        {
            try
            {
                var dbContext = new AlohaDb();

                var group = dbContext.UserGroups.First(g => g.Id == userGroupId);

                dbContext.UserGroups.Remove(group);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = group.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
Esempio n. 9
0
        public OperationResult CreateCurier(ServiceDataContracts.Curier curier)
        {
            try
            {
                var dbContext = new AlohaDb();

                var c = new Entities.Curier();
                c.FullName = curier.FullName;
                c.Phone    = curier.Phone;
                c.IsActive = curier.IsActive;

                dbContext.Curiers.Add(c);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = c.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
        public OperationResult CreateDeliveryPerson(ServiceDataContracts.DeliveryPerson deliveryPerson)
        {
            try
            {
                var dbContext = new AlohaDb();

                var dp = new Entities.DeliveryPerson();
                dp.FullName = deliveryPerson.FullName;
                dp.Phone    = deliveryPerson.Phone;
                dp.IsActive = deliveryPerson.IsActive;

                dbContext.DeliveryPersons.Add(dp);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = dp.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
Esempio n. 11
0
        public OperationResult RemoveUserFromGroup(long userId, long usrGroupId)
        {
            try
            {
                var dbContext = new AlohaDb();

                var existedLink = dbContext.UserUserGroups.FirstOrDefault(uug => uug.GroupId == usrGroupId && uug.UserId == userId);

                if (existedLink == null)
                {
                    return(new OperationResult
                    {
                        Success = false,
                        ErrorMessage = "User is not presented in this group"
                    });
                }

                dbContext.UserUserGroups.Remove(existedLink);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
Esempio n. 12
0
        public OperationResultValue <List <ServiceDataContracts.UserGroup> > GetUserGroupList()
        {
            try
            {
                var dbContext = new AlohaDb();
                var result    = dbContext.UserGroups.ToList().Select(ug => new ServiceDataContracts.UserGroup {
                    Id = ug.Id, Name = ug.Name
                }).ToList();

                return(new OperationResultValue <List <ServiceDataContracts.UserGroup> >
                {
                    Success = true,
                    Result = result
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResultValue <List <ServiceDataContracts.UserGroup> >
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
        public OperationResult CreatePhone(ServiceDataContracts.OrderCustomerPhone phone)
        {
            try
            {
                var dbContext = new AlohaDb();

                var c = Mapper.Map <ServiceDataContracts.OrderCustomerPhone, Entities.OrderCustomerPhone>(phone);
                c.UpdatedDate = DateTime.Now;

                dbContext.OrderCustomerPhones.Add(c);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = c.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message + (e.InnerException?.InnerException.Message ?? "")
                });
            }
        }
Esempio n. 14
0
        public OperationResult RemoveAllUserGroupsFromDb()
        {
            try
            {
                var dbContext = new AlohaDb();

                var result = dbContext.UserGroups.ToList();
                dbContext.UserGroups.RemoveRange(result);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
        public OperationResultValue <List <ServiceDataContracts.MarketingChannel> > GetMarketingChannelList()
        {
            try
            {
                var dbContext = new AlohaDb();

                var result = dbContext.MarketingChannel.Select(dp => new ServiceDataContracts.MarketingChannel
                {
                    Id   = dp.Id,
                    Name = dp.Name,

                    IsActive = dp.IsActive
                }).ToList();
                return(new OperationResultValue <List <ServiceDataContracts.MarketingChannel> >
                {
                    Success = true,
                    Result = result
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResultValue <List <ServiceDataContracts.MarketingChannel> >
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
Esempio n. 16
0
        public OperationResultValue <List <ServiceDataContracts.UserGroupAccess> > GetAllGroupFuncs(long groupId)
        {
            try
            {
                var dbContext = new AlohaDb();

                var result = dbContext.UserGroupAccesses.Where(uga => uga.UserGroupId == groupId).Select(ug => new ServiceDataContracts.UserGroupAccess
                {
                    Id          = ug.Id,
                    UserFuncId  = ug.UserFuncId,
                    UserGroupId = ug.UserGroupId,
                    UserFunc    = new ServiceDataContracts.UserFunc
                    {
                        Id   = ug.UserFunc.Id,
                        Name = ug.UserFunc.Name
                    },
                    FuncAccessType = (FuncAccessType)ug.AccessId
                }).ToList();

                return(new OperationResultValue <List <ServiceDataContracts.UserGroupAccess> >
                {
                    Success = true,
                    Result = result
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResultValue <List <ServiceDataContracts.UserGroupAccess> >
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
        public OperationResultValue <List <ServiceDataContracts.DeliveryPerson> > GetDeliveryPersonList()
        {
            try
            {
                var dbContext = new AlohaDb();

                var result = dbContext.DeliveryPersons.Select(dp => new ServiceDataContracts.DeliveryPerson
                {
                    Id       = dp.Id,
                    FullName = dp.FullName,
                    Phone    = dp.Phone,
                    IsActive = dp.IsActive
                }).ToList();
                return(new OperationResultValue <List <ServiceDataContracts.DeliveryPerson> >
                {
                    Success = true,
                    Result = result
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResultValue <List <ServiceDataContracts.DeliveryPerson> >
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
Esempio n. 18
0
 public void RecalcCustomerInfo(long orderCustomerId)
 {
     try
     {
         log.Debug($"RecalcCustomerAllInfo");
         AlohaDb db2 = new AlohaDb();
         Entities.OrderCustomerInfo info;
         if (db2.OrderCustomerInfo.Any(a => a.OrderCustomerId == orderCustomerId))
         {
             info = db2.OrderCustomerInfo.FirstOrDefault(a => a.OrderCustomerId == orderCustomerId);
         }
         else
         {
             info = new Entities.OrderCustomerInfo()
             {
                 OrderCustomerId = orderCustomerId
             };
             db2.OrderCustomerInfo.Add(info);
         }
         db2.SaveChanges();
         DateTime dtS = DateTime.Now.AddMonths(-deepMonthCount);
         info.OrderCount = db2.OrderToGo.Where(a => a.DeliveryDate >= dtS && a.OrderStatus > 2 && a.OrderCustomerId == orderCustomerId).Count();
         info.MoneyCount = db2.OrderToGo.Where(a => a.DeliveryDate >= dtS && a.OrderStatus > 2 && a.OrderCustomerId == orderCustomerId).Sum(a => (a.DishPackages.Sum(b => b.TotalPrice * b.Amount)) * (1 - (a.DiscountPercent / 100)) + a.DeliveryPrice);
         db2.SaveChanges();
     }
     catch (Exception e)
     {
         log.Error($"RecalcCustomerInfo {e.Message}");
         if (e.InnerException != null)
         {
             log.Error($"RecalcCustomerInfo InnerException  {e.InnerException.Message}");
         }
     }
 }
Esempio n. 19
0
        public OperationResult CreateUser(UserInfo userInfo)
        {
            try
            {
                var dbContext = new AlohaDb();

                if (dbContext.Users.Any(usr => usr.UserName == userInfo.UserName || usr.Email == userInfo.Email))
                {
                    return(new OperationResult
                    {
                        Success = false,
                        ErrorMessage = "User with such email or user name already exists. Please try another email and user name."
                    });
                }

                var user = new Entities.User();
                user.FullName = userInfo.FullName;
                user.Email    = userInfo.Email;
                var password = PasswordHelper.GetHashedPassword(userInfo.Password);
                user.Password             = password.Password;
                user.PasswordSalt         = password.PasswordSalt;
                user.Phone                = userInfo.Phone;
                user.RegistrationDateTime = DateTime.Now;
                user.SequrityAnswer       = userInfo.SequrityAnswer;
                user.SequrityQuestion     = userInfo.SequrityQuestion;
                user.UserName             = userInfo.UserName;
                user.UserRole             = (int)userInfo.UserRole;
                user.IsActive             = userInfo.IsActive;
                dbContext.Users.Add(user);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = user.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
Esempio n. 20
0
        public OperationResult AddFuncToGroup(long funcId, long usrGroupId, FuncAccessType accessType)
        {
            try
            {
                var dbContext = new AlohaDb();

                var result = dbContext.UserGroupAccesses.FirstOrDefault(uga => uga.UserFuncId == funcId && uga.UserGroupId == usrGroupId);

                if (result != null)
                {
                    return(new OperationResult
                    {
                        Success = false,
                        ErrorMessage = "Func already presemted in this group"
                    });
                }

                var newLink =
                    dbContext.UserGroupAccesses.Add(
                        new Entities.UserGroupAccess
                {
                    AccessId    = (int)accessType,
                    UserFuncId  = funcId,
                    UserGroupId = usrGroupId
                });

                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = newLink.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
Esempio n. 21
0
        public OperationResult AddUserToGroup(long userId, long usrGroupId)
        {
            try
            {
                var dbContext = new AlohaDb();

                var existedLink = dbContext.UserUserGroups.FirstOrDefault(uug => uug.GroupId == usrGroupId && uug.UserId == userId);

                if (existedLink != null)
                {
                    return(new OperationResult
                    {
                        Success = false,
                        ErrorMessage = "User already included in this group."
                    });
                }

                var newLink = new Entities.UserUserGroup();
                newLink.GroupId = usrGroupId;
                newLink.UserId  = userId;

                dbContext.UserUserGroups.Add(newLink);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = newLink.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
        public OperationResult CreateAddress(ServiceDataContracts.OrderCustomerAddress address)
        {
            try
            {
                var dbContext = new AlohaDb();

                var c = new Entities.OrderCustomerAddress
                {
                    Address         = address.Address,
                    Comment         = address.Comment,
                    IsActive        = address.IsActive,
                    IsPrimary       = address.IsPrimary,
                    MapUrl          = address.MapUrl,
                    OldId           = address.OldId,
                    OrderCustomerId = address.OrderCustomerId,
                    SubWay          = address.SubWay,
                    ZoneId          = address.ZoneId
                };

                c.UpdatedDate        = DateTime.Now;
                c.LastUpdatedSession = address.LastUpdatedSession;
                dbContext.OrderCustomerAddresses.Add(c);
                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                    CreatedObjectId = c.Id
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
 public OperationResultValue <List <ServiceDataContracts.OrderCustomerPhone> > GetPhoneList()
 {
     try
     {
         var dbContext = new AlohaDb();
         var res       = dbContext.OrderCustomerPhones.Where(a => a.IsActive).ToList();
         var result    = Mapper.Map <List <Entities.OrderCustomerPhone>, List <ServiceDataContracts.OrderCustomerPhone> >(res);
         return(new OperationResultValue <List <ServiceDataContracts.OrderCustomerPhone> >
         {
             Success = true,
             Result = result
         });
     }
     catch (Exception e)
     {
         log.Error("Error", e);
         return(new OperationResultValue <List <ServiceDataContracts.OrderCustomerPhone> >
         {
             Success = false,
             ErrorMessage = e.Message
         });
     }
 }
Esempio n. 24
0
        public OperationResult RemoveFuncFromGroup(long funcId, long usrGroupId)
        {
            try
            {
                var dbContext = new AlohaDb();

                var result = dbContext.UserGroupAccesses.FirstOrDefault(uga => uga.UserFuncId == funcId && uga.UserGroupId == usrGroupId);

                if (result == null)
                {
                    return(new OperationResult
                    {
                        Success = false,
                        ErrorMessage = "Func not presemted in this group."
                    });
                }

                dbContext.UserGroupAccesses.Remove(result);

                dbContext.SaveChanges();

                return(new OperationResult
                {
                    Success = true,
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResult
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
Esempio n. 25
0
 public UpdaterService(AlohaDb databaseContext)
 {
     db = databaseContext;
     LogHelper.Configure();
     log = LogHelper.GetLogger();
 }
Esempio n. 26
0
 public DishKitchenGroupService(AlohaDb databaseContext)
 {
     db = databaseContext;
     LogHelper.Configure();
     log = LogHelper.GetLogger();
 }
        public OperationResultValue <List <ServiceDataContracts.DishPackageFlightOrder> > GetDishPackageFlightOrderList(long orderFlightId)
        {
            try
            {
                var dbContext = new AlohaDb();

                var result = dbContext.DishPackagesFlightOrder.Where(p => p.OrderFlightId == orderFlightId).Select(dp =>
                                                                                                                   Mapper.Map <Entities.DishPackageFlightOrder, ServiceDataContracts.DishPackageFlightOrder>(dp)

                                                                                                                   /*
                                                                                                                    * new ServiceDataContracts.DishPackageFlightOrder
                                                                                                                    * {
                                                                                                                    *  Id = dp.Id,
                                                                                                                    *  Amount = dp.Amount,
                                                                                                                    *  Comment = dp.Comment,
                                                                                                                    *  DishId = dp.DishId,
                                                                                                                    *  DishName = dp.DishName,
                                                                                                                    *  OrderFlightId = dp.OrderFlightId,
                                                                                                                    *  PassageNumber = dp.PassageNumber,
                                                                                                                    *  TotalPrice = dp.TotalPrice,
                                                                                                                    *  PositionInOrder = dp.PositionInOrder,
                                                                                                                    *  Code = dp.Code,
                                                                                                                    *
                                                                                                                    *  Dish = new ServiceDataContracts.Dish()
                                                                                                                    *  {
                                                                                                                    *      Barcode = dp.Dish.Barcode,
                                                                                                                    *      EnglishName = dp.Dish.EnglishName,
                                                                                                                    *      Id = dp.Dish.Id,
                                                                                                                    *      IsActive = dp.Dish.IsActive,
                                                                                                                    *      IsTemporary = dp.Dish.IsTemporary,
                                                                                                                    *      IsAlcohol = dp.Dish.IsAlcohol,
                                                                                                                    *      PriceForDelivery = dp.Dish.PriceForDelivery,
                                                                                                                    *      PriceForFlight = dp.Dish.PriceForFlight,
                                                                                                                    *      RussianName = dp.Dish.RussianName,
                                                                                                                    *      LabelEnglishName = dp.Dish.LabelEnglishName,
                                                                                                                    *      LabelRussianName = dp.Dish.LabelRussianName,
                                                                                                                    *      SHId = dp.Dish.SHId,
                                                                                                                    *      Name = dp.Dish.Name,
                                                                                                                    *      NeedPrintInMenu = dp.Dish.NeedPrintInMenu
                                                                                                                    *  }
                                                                                                                    *
                                                                                                                    * }
                                                                                                                    */

                                                                                                                   ).ToList();
                return(new OperationResultValue <List <ServiceDataContracts.DishPackageFlightOrder> >
                {
                    Success = true,
                    Result = result
                });
            }
            catch (Exception e)
            {
                log.Error("Error", e);
                return(new OperationResultValue <List <ServiceDataContracts.DishPackageFlightOrder> >
                {
                    Success = false,
                    ErrorMessage = e.Message
                });
            }
        }
 public DishPackageFlightOrderService(AlohaDb databaseContext)
 {
     db = databaseContext;
     LogHelper.Configure();
     log = LogHelper.GetLogger();
 }
 public AirCompanyService(AlohaDb databaseContext)
 {
     db = databaseContext;
 }
 public PaymentGroupService(AlohaDb databaseContext)
 {
     db = databaseContext;
     LogHelper.Configure();
     log = LogHelper.GetLogger();
 }