示例#1
0
 public static int InsertActivation(NewActivationReq newActivation)
 {
     try
     {
         var activation = new Activation()
         {
             UserId         = newActivation.UserId,
             ActivationCode = newActivation.ActicationCode.ToString(),
             IsActive       = true
         };
         using (var dbCtx = new MSDbContext())
         {
             dbCtx.Activations.Add(activation);
             int result = dbCtx.SaveChanges();
             if (result == 1)
             {
                 return(activation.Id);
             }
             else
             {
                 throw new Exception();
             }
         }
     }
     catch (Exception e)
     {
         var ex = new InsertIntoDataBaseException(ExceptionMessage.InsertIntoActivationsException, e);
         Logger.Log.Error(ex.Message, ex);
         throw ex;
     }
 }
示例#2
0
 public static int InsertUser(NewUserReq newUser)
 {
     try
     {
         var user = new User()
         {
             IsActive = true,
             Name     = newUser.Name,
             Tel      = newUser.Tel
         };
         using (var dbCtx = new MSDbContext())
         {
             dbCtx.Users.Add(user);
             int result = dbCtx.SaveChanges();
             if (result == 1)
             {
                 return(user.Id);
             }
             else
             {
                 throw new Exception();
             }
         }
     }
     catch (Exception e)
     {
         var ex = new InsertIntoDataBaseException(ExceptionMessage.InsertIntoUsersException, e);
         Logger.Log.Error(ex.Message, ex);
         throw ex;
     }
 }
示例#3
0
 public static int InsertToken(NewTokenReq newToken)
 {
     try
     {
         var token = new Token()
         {
             IsActive      = true,
             UserId        = newToken.UserId,
             TokenStr      = newToken.TokenStr,
             LastUsageTime = newToken.TokenTime
         };
         using (var dbCtx = new MSDbContext())
         {
             dbCtx.Tokens.Add(token);
             int result = dbCtx.SaveChanges();
             if (result == 1)
             {
                 return(token.Id);
             }
             else
             {
                 throw new Exception();
             }
         }
     }
     catch (Exception e)
     {
         var ex = new InsertIntoDataBaseException(ExceptionMessage.InsertIntoTokensException, e);
         Logger.Log.Error(ex.Message, ex);
         throw ex;
     }
 }
示例#4
0
        public static int InsertServerInfo(BE.Entities.Request.ServerInfoReq serverInfo)
        {
            try
            {
                var server = new Entities.Server()
                {
                    Name       = serverInfo.Name,
                    Address    = serverInfo.Address,
                    Tel        = serverInfo.Tel,
                    IsActive   = true,
                    CategoryId = serverInfo.CategoryId
                };
                using (var dbCtx = new MSDbContext())
                {
                    dbCtx.Servers.Add(server);
                    int result = dbCtx.SaveChanges();

                    if (result == 1)
                    {
                        foreach (var serverPhoto in serverInfo.Photos)
                        {
                            byte[] photoByte      = Convert.FromBase64String(serverPhoto);
                            var    serverPhotoEnt = new Entities.ServerPhoto()
                            {
                                Photo    = photoByte,
                                ServerId = server.Id
                            };
                            dbCtx.ServerPhotos.Add(serverPhotoEnt);
                            dbCtx.SaveChanges();
                        }
                        return(server.Id);
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }
            catch (Exception e)
            {
                var ex = new InsertIntoDataBaseException(ExceptionMessage.InsertIntoServersException, e);
                Logger.Log.Error(ex.Message, ex);
                throw ex;
            }
        }
示例#5
0
 public static bool DeleteServiceProviderLike(ServiceProviderLikeReq likeReq)
 {
     try
     {
         using (var dbCtx = new MSDbContext())
         {
             dbCtx.ServiceProviderLike.RemoveRange(
                 dbCtx.ServiceProviderLike.Where(x => x.User.Tel == likeReq.UserMobileNumber && x.ServerId == likeReq.ServerId));
             dbCtx.SaveChanges();
             return(true);
         }
     }
     catch (Exception e)
     {
         var ex = new InsertIntoDataBaseException(ExceptionMessage.DeleteServiceProviderLikeException, e);
         Logger.Log.Error(ex.Message, ex);
         throw ex;
     }
 }
示例#6
0
        public static int InsertServiceProviderLike(ServiceProviderLikeReq likeReq)
        {
            try
            {
                using (var dbCtx = new MSDbContext())
                {
                    var user           = UserAccounts.SelectUserByTel(likeReq.UserMobileNumber);
                    var checkExistLike = (from likes in dbCtx.ServiceProviderLike
                                          where likes.ServerId == likeReq.ServerId && likes.UserId == user.Id
                                          select likes).Count();
                    if (checkExistLike > 0)
                    {
                        return(0);
                    }
                    var serviceProvideLike = new Entities.ServiceProviderLike()
                    {
                        ServerId = likeReq.ServerId,
                        UserId   = user.Id
                    };
                    dbCtx.ServiceProviderLike.Add(serviceProvideLike);
                    int result = dbCtx.SaveChanges();

                    if (result == 1)
                    {
                        return(serviceProvideLike.Id);
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            }
            catch (Exception e)
            {
                var ex = new InsertIntoDataBaseException(ExceptionMessage.InsertIntoServiceProviderLikeException, e);
                Logger.Log.Error(ex.Message, ex);
                throw ex;
            }
        }