public static ClientDTO SendMessagesForTodaysAnniversary(ClientDTO ClientDTOSettings)
        {
            try
            {
                ClientDTO ClientDTO = new ClientDTO();
                ClientDTO = ClientService.GetById(ClientDTOSettings.Id);
                ClientDTO.AnniversaryMessage                    = ClientDTOSettings.AnniversaryMessage;
                ClientDTO.IsSendAnniversaryMessages             = ClientDTOSettings.IsSendAnniversaryMessages;
                ClientDTO.IsSendAnniversaryCoupons              = ClientDTOSettings.IsSendAnniversaryCoupons;
                ClientDTO.AnniversaryCouponExpire               = ClientDTOSettings.AnniversaryCouponExpire;
                ClientDTO.AnniversaryCouponExpireType           = ClientDTOSettings.AnniversaryCouponExpireType;
                ClientDTO.MinPurchaseAmountForAnniversaryCoupon = ClientDTOSettings.MinPurchaseAmountForAnniversaryCoupon;

                GlobalSettings.LoggedInClientId = ClientDTO.Id;
                int PartnerId = ClientService.GetById(ClientDTO.Id).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                UnitOfWork uow    = new UnitOfWork();
                Client     Client = Transform.ClientToDomain(ClientDTO);
                uow.ClientRepo.Update(Client);
                uow.SaveChanges();


                Client    = uow.ClientRepo.GetById(ClientDTOSettings.Id);
                ClientDTO = Transform.ClientToDTO(Client);
                return(ClientDTO);
            }
            catch
            {
                throw;
            }
        }
        //Edit Client
        public static void Edit(ClientDTO ClientDTO)
        {
            try
            {
                GlobalSettings.LoggedInClientId = ClientDTO.Id;
                int PartnerId = ClientService.GetById(ClientDTO.Id).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                UnitOfWork uow    = new UnitOfWork();
                Client     Client = Transform.ClientToDomain(ClientDTO);
                uow.ClientRepo.Update(Client);
                uow.SaveChanges();
                if (ClientDTO.IsMailSend == true)
                {
                    List <UserDTO> UserDTOList = new List <UserDTO>();
                    UserDTOList = UserService.GetUsersbyClientId(ClientDTO.Id, "").Where(e => e.UserType == UserType.Admin.ToString()).OrderBy(e => e.Id).ToList();
                    foreach (var item in UserDTOList)
                    {
                        if (item.IsActive == true && item.UserType == UserType.Admin.ToString())
                        {
                            CommonService.SendEmail("Sender code application approved", "<HTML><BODY><P>Hello " + ClientDTO.Company + "</P><P>Your request for sender code " + ClientDTO.SenderCode + " has approved.</P></BODY></HTML>", item.Email, "", false);
                        }
                    }
                }
            }
            catch
            {
                throw;
            }
        }
        //Modify client settings as per client details
        public static ClientDTO ModifyClientSettings(ClientDTO ClientDTOSetting)
        {
            try
            {
                ClientDTO ClientDTO = new ClientDTO();
                if (ClientDTOSetting.Id > 0)
                {
                    ClientDTO = ClientService.GetById(ClientDTOSetting.Id);
                    ClientDTO.AlertCreditBalanceLimit = ClientDTOSetting.AlertCreditBalanceLimit;
                    ClientDTO.AlertOnCredit           = ClientDTOSetting.AlertOnCredit;
                    ClientDTO.DefaultCouponMessage    = ClientDTOSetting.DefaultCouponMessage;
                    ClientDTO.DefaultCouponExpire     = ClientDTOSetting.DefaultCouponExpire;
                    ClientDTO.CouponExpireType        = ClientDTOSetting.CouponExpireType;

                    GlobalSettings.LoggedInClientId = ClientDTO.Id;
                    int PartnerId = ClientService.GetById(ClientDTO.Id).PartnerId;
                    GlobalSettings.LoggedInPartnerId = PartnerId;

                    UnitOfWork uow    = new UnitOfWork();
                    Client     Client = Transform.ClientToDomain(ClientDTO);
                    uow.ClientRepo.Update(Client);
                    uow.SaveChanges();

                    //Client = uow.ClientRepo.GetById(Client.Id);
                    ClientDTO = Transform.ClientToDTO(Client);
                }
                return(ClientDTO);
            }
            catch
            {
                throw;
            }
        }
Exemple #4
0
        //Delete location by id
        public static bool Delete(int Id)
        {
            GlobalSettings.LoggedInClientId = LocationService.GetById(Id).ClientId;
            int PartnerId = ClientService.GetById(Convert.ToInt32(GlobalSettings.LoggedInClientId)).PartnerId;

            GlobalSettings.LoggedInPartnerId = PartnerId;

            bool IsExists = IsChildEntityExist(Id);

            try
            {
                if (IsExists != true)
                {
                    LocationDTO LocationDTO = new LocationDTO();
                    LocationDTO = GetById(Id);
                    UnitOfWork uow = new UnitOfWork();
                    uow.LocationRepo.Delete(Id);
                    uow.SaveChanges();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch
            {
                throw;
            }
        }
        //Set minimum balance alert by using client id, balance and alert flag
        public static ClientDTO SetMinimumBalanceAlert(int Id, int Balance, bool ShowAlert)
        {
            try
            {
                ClientDTO ClientDTO = new ClientDTO();
                ClientDTO = ClientService.GetById(Id);
                ClientDTO.AlertCreditBalanceLimit = Balance;
                ClientDTO.AlertOnCredit           = ShowAlert;

                GlobalSettings.LoggedInClientId = ClientDTO.Id;
                int PartnerId = ClientService.GetById(ClientDTO.Id).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                UnitOfWork uow    = new UnitOfWork();
                Client     Client = Transform.ClientToDomain(ClientDTO);
                uow.ClientRepo.Update(Client);
                uow.SaveChanges();


                Client    = uow.ClientRepo.GetById(Id);
                ClientDTO = Transform.ClientToDTO(Client);
                return(ClientDTO);
            }
            catch
            {
                throw;
            }
        }
        //Create redeemed Count
        public static int Create(RedeemedCountDTO RedeemedCountDTO)
        {
            try
            {
                var RedeemedCount = new RedeemedCount();

                GlobalSettings.LoggedInClientId = RedeemedCountDTO.ClientId;
                GlobalSettings.LoggedInUserId   = RedeemedCountDTO.UserId;
                int PartnerId = ClientService.GetById(RedeemedCountDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                UnitOfWork uow = new UnitOfWork();
                RedeemedCount = Transform.RedeemedCountToDomain(RedeemedCountDTO);
                uow.RedeemedCountRepo.Insert(RedeemedCount);

                uow.SaveChanges();
                RedeemedCount.Id = RedeemedCount.Id;
                return(RedeemedCount.Id);
            }

            catch (Exception)
            {
                throw;
            }
        }
        //Delete sender code document
        public static bool DeleteSenderCodeDocument(string filePath, int ClientId)
        {
            try
            {
                if (File.Exists(filePath))
                {
                    File.Delete(filePath);
                    ClientDTO ClientDTO = new ClientDTO();
                    ClientDTO = GetById(ClientId);
                    ClientDTO.SenderCodeFilePath = null;

                    GlobalSettings.LoggedInClientId = ClientDTO.Id;
                    int PartnerId = ClientService.GetById(ClientDTO.Id).PartnerId;
                    GlobalSettings.LoggedInPartnerId = PartnerId;

                    Edit(ClientDTO);

                    // Send Mail to Admin
                    PartnerDTO PartnerDTO = new PartnerDTO();
                    PartnerDTO = PartnerService.GetById(ClientDTO.PartnerId);
                    CommonService.SendEmail("Removed sendercode application request", "<HTML><BODY><P>Hello " + CommonService.GetFirstname(PartnerDTO.Name) + "</P><P>Request for sender code from " + ClientDTO.Company + " has been removed.</P></BODY></HTML>", PartnerDTO.Email, "", false);

                    return(true);
                }

                return(false);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        //Create group
        public static int Create(GroupDTO GroupDTO)
        {
            try
            {
                GlobalSettings.LoggedInClientId = GroupDTO.ClientID;
                int PartnerId = ClientService.GetById(GroupDTO.ClientID).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                var group = new Group();

                UnitOfWork uow = new UnitOfWork();
                GroupDTO.ClientID = GroupDTO.ClientID;
                group             = Transform.GroupToDomain(GroupDTO);
                uow.GroupRepo.Insert(group);

                uow.SaveChanges();


                GroupDTO.Id = group.Id;
                return(GroupDTO.Id);
            }

            catch (Exception)
            {
                throw;
            }
        }
        //Create template
        public static int Create(TemplateDTO TemplateDTO)
        {
            if (TemplateDTO.Title == null || TemplateDTO.Title == "")
            {
                return(0);
            }

            try
            {
                var Template = new Template();

                GlobalSettings.LoggedInClientId = TemplateDTO.ClientId;
                int PartnerId = ClientService.GetById(TemplateDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                UnitOfWork uow = new UnitOfWork();
                Template = Transform.TemplateToDomain(TemplateDTO);
                uow.TemplateRepo.Insert(Template);

                uow.SaveChanges();
                TemplateDTO.Id = Template.Id;
                return(TemplateDTO.Id);
            }

            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Edit User
        /// </summary>
        /// <param name="UserDTO"> Modify the user as per provided user details </param>
        public static void Edit(UserDTO UserDTO)
        {
            //if (UserDTO.Mobile != null && UserDTO.Mobile != "")
            //{
            try
            {
                GlobalSettings.LoggedInClientId = UserDTO.ClientId;
                GlobalSettings.LoggedInUserId   = UserDTO.Id;
                int PartnerId = ClientService.GetById(UserDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                UserDTO UserDTOOld = new UserDTO();
                UserDTOOld = GetById(UserDTO.Id);

                UnitOfWork uow  = new UnitOfWork();
                User       User = Transform.UserToDomain(UserDTO);
                uow.UserRepo.Update(User);
                uow.SaveChanges();

                //if (UserDTOOld.Password != UserDTO.Password || UserDTOOld.Email != UserDTO.Email)
                //{
                //    CommonService.SendEmail("Your msgBlaster Login details are modified", "Hello " + User.Name + ", <br/><br/> <p>Your latest msgBlaster username and Password is as follows - </p> <br/> <table><tr><td> Username</td><td> = " + User.Email + "</td></tr><tr><td>Password</td><td> = " + User.Password + "</td></tr></table>", User.Email, "", false);
                //}
            }
            catch
            {
                throw;
            }
            //}
        }
Exemple #11
0
        //Delete document by id and file path
        public static bool Delete(int Id, string FilePath)
        {
            bool IsDeleted = false;

            try
            {
                DocumentDTO DocumentDTO = new DocumentDTO();
                DocumentDTO = GetById(Id);
                GlobalSettings.LoggedInClientId = DocumentDTO.ClientId;
                GlobalSettings.LoggedInUserId   = DocumentDTO.UserId;
                int PartnerId = ClientService.GetById(DocumentDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                IsDeleted = CommonService.RemoveDocument(FilePath); //+ DocumentDTO.Path
                if (IsDeleted != false)
                {
                    UnitOfWork uow = new UnitOfWork();
                    uow.DocumentRepo.Delete(Id);
                    uow.SaveChanges();
                }
                return(IsDeleted);
            }
            catch
            {
                throw;
            }
        }
Exemple #12
0
        //Create document
        public static int Create(DocumentDTO DocumentDTO)
        {
            try
            {
                GlobalSettings.LoggedInClientId = DocumentDTO.ClientId;
                GlobalSettings.LoggedInUserId   = DocumentDTO.UserId;
                int PartnerId = ClientService.GetById(DocumentDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                var Document = new Document();
                using (var uow = new UnitOfWork())
                {
                    Document = Transform.DocumentToDomain(DocumentDTO);
                    uow.DocumentRepo.Insert(Document);
                    uow.SaveChanges();
                    return(Document.Id);
                }
            }
            //catch (LoggedInUserException)
            //{
            //    throw new System.TimeoutException();
            //}
            catch (Exception)
            {
                throw;
            }
        }
Exemple #13
0
        public static CreditRequest CreditRequestToDomain(CreditRequestDTO CreditRequestDTO)
        {
            if (CreditRequestDTO == null)
            {
                return(null);
            }
            Mapper.CreateMap <CreditRequestDTO, CreditRequest>();
            CreditRequest CreditRequest = Mapper.Map <CreditRequest>(CreditRequestDTO);

            CreditRequest._clientName = ClientService.GetById(CreditRequest.ClientId).Company;
            CreditRequest._userName   = UserService.GetById(CreditRequest.RequestedBy).Name;
            return(CreditRequest);
        }
        //Upload SQLite database file to the server
        public static string UploadSQLiteDatabase(HttpPostedFile file, string documentPath, int ClientId, string FileName)
        {
            try
            {
                var    b      = new byte[file.ContentLength];
                string result = "";
                documentPath = documentPath + ClientId; //"\\" + ModuleName
                MemoryStream ms = new MemoryStream(b);
                // MemoryStream ms = new MemoryStream(file.ContentLength);
                bool IsExists = System.IO.Directory.Exists(documentPath);
                if (IsExists == false)
                {
                    System.IO.Directory.CreateDirectory(documentPath);
                }

                var path = System.IO.Path.Combine(documentPath, FileName); //file.FileName

                if (File.Exists(path))
                {
                    result = "File already Exists";
                    return(result);
                }
                else
                {
                    file.SaveAs(documentPath + "/" + FileName); //file.FileName
                    ms.Close();

                    //Change Client  IsDatabaseUploaded status
                    ClientDTO ClientDTO = new ClientDTO();
                    ClientDTO = ClientService.GetById(ClientId);
                    ClientDTO.IsDatabaseUploaded = true;

                    GlobalSettings.LoggedInClientId = ClientDTO.Id;
                    int PartnerId = ClientService.GetById(ClientDTO.Id).PartnerId;
                    GlobalSettings.LoggedInPartnerId = PartnerId;

                    ClientService.Edit(ClientDTO);

                    result = "File uploaded successfully";

                    return(result);
                }
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }
        //Delete template
        public static void Delete(int id)
        {
            try
            {
                GlobalSettings.LoggedInClientId = TemplateService.GetById(id).ClientId;
                int PartnerId = ClientService.GetById(Convert.ToInt32(GlobalSettings.LoggedInClientId)).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                UnitOfWork uow = new UnitOfWork();
                uow.TemplateRepo.Delete(id);
                uow.SaveChanges();
            }
            catch
            {
                throw;
            }
        }
        //Upload Sender code document to the server
        public static string UploadSenderCodeDocument(HttpPostedFile file, string documentPath, int ClientId, string FileName)
        {
            try
            {
                var    b      = new byte[file.ContentLength];
                string result = "";
                documentPath = documentPath + ClientId; //"\\" + ModuleName
                MemoryStream ms = new MemoryStream(b);
                // MemoryStream ms = new MemoryStream(file.ContentLength);
                bool IsExists = System.IO.Directory.Exists(documentPath);
                if (IsExists == false)
                {
                    System.IO.Directory.CreateDirectory(documentPath);
                }

                var path = System.IO.Path.Combine(documentPath, FileName); //file.FileName

                if (File.Exists(path))
                {
                    result = "File already Exists";
                    return(result);
                }
                else
                {
                    file.SaveAs(documentPath + "/" + FileName); //file.FileName
                    ms.Close();

                    ClientDTO ClientDTO = new ClientDTO();
                    ClientDTO = ClientService.GetById(ClientId);
                    ClientDTO.SenderCodeFilePath = ClientId + "/" + FileName;// file.FileName;
                    ClientService.Edit(ClientDTO);
                    result = "File uploaded successfully";

                    // Send Mail to Admin
                    PartnerDTO PartnerDTO = new PartnerDTO();
                    PartnerDTO = PartnerService.GetById(ClientDTO.PartnerId);
                    CommonService.SendEmail("New sendercode application request", "<HTML><BODY><P>Hello " + CommonService.GetFirstname(PartnerDTO.Name) + "</P><P>" + ClientDTO.Company + " has requested for new sender code.</P></BODY></HTML>", PartnerDTO.Email, "", false);
                    return(result);
                }
            }
            catch (Exception ex)
            {
                return(ex.ToString());
            }
        }
Exemple #17
0
        //Delete all documents by client id ad document folder path
        public static bool DeleteAllDocument(int ClientId, string DocumentFolderPath)
        {
            bool IsDeleted = false;

            try
            {
                List <DocumentDTO> DocumentDTOList = new List <DocumentDTO>();

                using (var uow = new UnitOfWork())
                {
                    IEnumerable <Document> Document = uow.DocumentRepo.GetAll().Where(e => e.ClientId == ClientId);
                    if (Document != null)
                    {
                        foreach (var item in Document)
                        {
                            GlobalSettings.LoggedInClientId = item.ClientId;
                            GlobalSettings.LoggedInUserId   = item.UserId;
                            int PartnerId = ClientService.GetById(item.ClientId).PartnerId;
                            GlobalSettings.LoggedInPartnerId = PartnerId;


                            IsDeleted = CommonService.RemoveDocument(DocumentFolderPath + item.Path);
                            if (IsDeleted == true)
                            {
                                uow.DocumentRepo.Delete(item.Id);
                                uow.SaveChanges();
                                IsDeleted = true;
                            }
                            else
                            {
                                IsDeleted = false;
                            }
                        }

                        IsDeleted = CommonService.DeleteFolder(DocumentFolderPath + ClientId);
                    }

                    return(IsDeleted);
                }
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// Create User
        /// </summary>
        /// <param name="UserDTO">UserDTO object</param>
        /// <returns>This will return user details</returns>
        public static UserDTO Create(UserDTO UserDTO)
        {
            //if (UserDTO.Mobile == null && UserDTO.Mobile == "")
            //{
            //    return null;
            //}


            GlobalSettings.LoggedInClientId = UserDTO.ClientId;
            int PartnerId = ClientService.GetById(UserDTO.ClientId).PartnerId;

            GlobalSettings.LoggedInPartnerId = PartnerId;

            try
            {
                var User = new User();
                using (var uow = new UnitOfWork())
                {
                    UserDTO.IsActive = true;
                    //UserDTO.UserType = "Admin";
                    User = Transform.UserToDomain(UserDTO);
                    uow.UserRepo.Insert(User);
                    uow.SaveChanges();
                    CommonService.SendEmail("msgBlaster Login details", "Hello " + User.FirstName + ", <br/><br/> <p>Your msgBlaster username and Password is as follows - </p> <br/> <table><tr><td> Username</td><td> = " + User.Email + "</td></tr><tr><td>Password</td><td> = " + User.Password + "</td></tr></table>", User.Email, "", false);

                    if (User.Id > 0)
                    {
                        UserDTO.Id = User.Id;
                        return(UserDTO);
                    }
                    else
                    {
                        throw new OperationCanceledException("Insert operation terminated");
                    }
                }
            }
            //catch (LoggedInUserException)
            //{
            //    throw new System.TimeoutException();
            //}
            catch (Exception)
            {
                throw;
            }
        }
        //Edit group
        public static void Edit(GroupDTO GroupDTO)
        {
            try
            {
                GlobalSettings.LoggedInClientId = GroupDTO.ClientID;
                int PartnerId = ClientService.GetById(GroupDTO.ClientID).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                UnitOfWork uow   = new UnitOfWork();
                Group      Group = Transform.GroupToDomain(GroupDTO);
                uow.GroupRepo.Update(Group);
                uow.SaveChanges();
            }
            catch
            {
                throw;
            }
        }
Exemple #20
0
        //Edit location
        public static void Edit(LocationDTO LocationDTO)
        {
            try
            {
                GlobalSettings.LoggedInClientId = LocationDTO.ClientId;
                int PartnerId = ClientService.GetById(LocationDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                UnitOfWork uow      = new UnitOfWork();
                Location   Location = Transform.LocationToDomain(LocationDTO);
                uow.LocationRepo.Update(Location);
                uow.SaveChanges();
            }
            catch
            {
                throw;
            }
        }
        //Edit redeemed count
        public static void Edit(RedeemedCountDTO RedeemedCountDTO)
        {
            try
            {
                GlobalSettings.LoggedInClientId = RedeemedCountDTO.ClientId;
                GlobalSettings.LoggedInUserId   = RedeemedCountDTO.UserId;
                int PartnerId = ClientService.GetById(RedeemedCountDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                UnitOfWork    uow           = new UnitOfWork();
                RedeemedCount RedeemedCount = Transform.RedeemedCountToDomain(RedeemedCountDTO);
                uow.RedeemedCountRepo.Update(RedeemedCount);
                uow.SaveChanges();
            }
            catch
            {
                throw;
            }
        }
 public static bool AllowToProcessClient(CampaignDTO CampaignDTO)
 {
     if (CampaignDTO == null)
     {
         return(false);
     }
     else
     {
         ClientDTO ClientDTO = new ClientDTO();
         ClientDTO = ClientService.GetById(CampaignDTO.ClientId);
         if (ClientDTO.SMSCredit > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
        //Edit template
        public static void Edit(TemplateDTO TemplateDTO)
        {
            if (TemplateDTO.Title != null || TemplateDTO.Title != "")
            {
                try
                {
                    GlobalSettings.LoggedInClientId = TemplateDTO.ClientId;
                    int PartnerId = ClientService.GetById(TemplateDTO.ClientId).PartnerId;
                    GlobalSettings.LoggedInPartnerId = PartnerId;

                    UnitOfWork uow      = new UnitOfWork();
                    Template   Template = Transform.TemplateToDomain(TemplateDTO);
                    uow.TemplateRepo.Update(Template);
                    uow.SaveChanges();
                }
                catch
                {
                    throw;
                }
            }
        }
        //Get redeemed count list by user id and campaign id
        public static List <RedeemedCountDTO> GetByUserId(int UserId, int CampaignId)
        {
            List <RedeemedCountDTO> RedeemedCountDTOList = new List <RedeemedCountDTO>();

            try
            {
                UnitOfWork uow = new UnitOfWork();
                IEnumerable <RedeemedCount> RedeemedCount = uow.RedeemedCountRepo.GetAll().Where(e => e.UserId == UserId && e.EcouponCampaignId == CampaignId);
                if (RedeemedCount != null)
                {
                    foreach (var item in RedeemedCount)
                    {
                        EcouponCampaignDTO EcouponCampaignDTO = new EcouponCampaignDTO();
                        EcouponCampaignDTO = EcouponCampaignService.GetById(item.EcouponCampaignId);
                        if (EcouponCampaignDTO.ExpiresOn > System.DateTime.Now)
                        {
                            RedeemedCountDTO RedeemedCountDTO = new RedeemedCountDTO();
                            RedeemedCountDTO = Transform.RedeemedCountToDTO(item);

                            UserDTO UserDTO = new UserDTO();
                            UserDTO = UserService.GetById(UserId);
                            RedeemedCountDTO.UserName = UserDTO.Name;
                            RedeemedCountDTO.Location = LocationService.GetById(UserDTO.LocationId).Name;
                            ClientDTO ClientDTO = new ClientDTO();
                            ClientDTO = ClientService.GetById(UserDTO.ClientId);
                            RedeemedCountDTO.ClientName = ClientDTO.Company;

                            RedeemedCountDTOList.Add(RedeemedCountDTO);
                        }
                    }
                }

                return(RedeemedCountDTOList);
            }
            catch
            {
                //  throw;
                return(RedeemedCountDTOList);
            }
        }
        //Get client is active or inactive
        public static bool ActiveInactiveClient(int ClientId)
        {
            try
            {
                if (ClientId <= 0)
                {
                    return(false);
                }

                ClientDTO ClientDTO = new ClientDTO();
                ClientDTO = GetById(ClientId);

                GlobalSettings.LoggedInClientId = ClientDTO.Id;
                int PartnerId = ClientService.GetById(ClientDTO.Id).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                if (ClientDTO == null)
                {
                    return(false);
                }

                if (ClientDTO.IsActive == true)
                {
                    ClientDTO.IsActive = false;
                    Edit(ClientDTO);
                    return(true);
                }
                else
                {
                    ClientDTO.IsActive = true;
                    Edit(ClientDTO);
                    return(true);
                }
            }
            catch
            {
                throw;
            }
        }
Exemple #26
0
        //Get document list by client id
        public static List <DocumentDTO> GetDocumentListByClientId(int ClientId)
        {
            List <DocumentDTO> DocumentDTOList = new List <DocumentDTO>();

            try
            {
                using (var uow = new UnitOfWork())
                {
                    IEnumerable <Document> Document = uow.DocumentRepo.GetAll().Where(e => e.ClientId == ClientId);
                    if (Document != null)
                    {
                        foreach (var item in Document)
                        {
                            DocumentDTO DocumentDTO = new DocumentDTO();
                            DocumentDTO = Transform.DocumentToDTO(item);
                            UserDTO UserDTO = new UserDTO();
                            UserDTO          = UserService.GetById(DocumentDTO.UserId);
                            DocumentDTO.User = UserDTO.Name;

                            ClientDTO ClientDTO = new ClientDTO();
                            ClientDTO          = ClientService.GetById(DocumentDTO.ClientId);
                            DocumentDTO.Client = ClientDTO.Company;

                            DocumentDTOList.Add(DocumentDTO);
                        }
                    }
                }

                return(DocumentDTOList);
            }
            //catch (LoggedInUserException)
            //{
            //    throw new System.TimeoutException();
            //}
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Sign In user
        /// </summary>
        /// <param name="Email">Email Id of active user</param>
        /// <param name="Password">Password of the active user</param>
        /// <returns></returns>
        public static UserDTO SignIn(string Email, string Password)//GetClientUserByEmailAndPassword
        {
            try
            {
                UserDTO        UserDTO     = new UserDTO();
                List <UserDTO> UserDTOList = new List <UserDTO>();

                UnitOfWork         uow  = new UnitOfWork();
                IEnumerable <User> User = uow.UserRepo.GetAll().Where(e => e.Email.ToLower() == Email.ToLower() && e.Password == Password && e.IsActive == true);
                if (User != null)
                {
                    foreach (var item in User)
                    {
                        //ClientDTOList.Add(Transform.ClientToDTO(item));
                        UserDTO = Transform.UserToDTO(item);
                        GlobalSettings.LoggedInUserId = UserDTO.Id;
                        UserDTO.UserAccessPrivileges  = GetUserAccess(UserDTO.UserType.ToString());
                        // Check Client is Active or not
                        ClientDTO ClientDTO = new ClientDTO();
                        ClientDTO = ClientService.GetById(UserDTO.ClientId);
                        GlobalSettings.LoggedInClientId = ClientDTO.Id;


                        if (ClientDTO.IsActive != true)
                        {
                            UserDTO = null;
                        }
                        //HttpContext.Current.Session["LoggedClient"] = ClientDTO;
                        //HttpContext.Current.Session["LoggedClientId"] = ClientDTO.Id;
                    }
                }
                return(UserDTO);
            }
            catch
            {
                throw;
            }
        }
Exemple #28
0
        //Create location
        public static int Create(LocationDTO LocationDTO)
        {
            try
            {
                GlobalSettings.LoggedInClientId = LocationDTO.ClientId;
                int PartnerId = ClientService.GetById(LocationDTO.ClientId).PartnerId;
                GlobalSettings.LoggedInPartnerId = PartnerId;

                var Location = new Location();

                UnitOfWork uow = new UnitOfWork();
                Location = Transform.LocationToDomain(LocationDTO);
                uow.LocationRepo.Insert(Location);

                uow.SaveChanges();
                Location.Id = Location.Id;
                return(Location.Id);
            }

            catch (Exception)
            {
                throw;
            }
        }
        public static void CreatePacket()
        {
            StringBuilder recipientnumberslist = new StringBuilder();


            try
            {
                bool ismailmarge             = false;
                int  requiredCreditTosendmsg = 0;
                //DataTable dtContact = new DataTable();
                int                MOBILENUMBERLEN = 0;
                string             xmlpacket       = null;
                List <CampaignDTO> CampaignDTOList = CampaignService.GetCampaignNotSentList();
                if (CampaignDTOList.Count != 0)
                {
                    foreach (var item in CampaignDTOList)
                    {
                        // create xml packet
                        DataTable dtContact = new DataTable();

                        xmlpacket  = "<?xml version=" + "\"1.0\"?>";
                        xmlpacket += "<packet>";
                        xmlpacket += "<mbversion>MessageBlaster_Web</mbversion>";
                        xmlpacket += "<messagesource>MSGBLASTER</messagesource>";
                        //DataTable regInfoDT = oCompanyInfo.LoadAll();
                        ClientDTO ClientDTO = new ClientDTO();
                        ClientDTO = ClientService.GetById(item.ClientId);


                        SettingDTO SettingDTO = new SettingDTO();
                        SettingDTO      = SettingService.GetById(1);
                        MOBILENUMBERLEN = SettingDTO.MobileNumberLength;

                        ArrayList     recipientsnumbers = new ArrayList();
                        MessageLogDTO oMessageLog       = new MessageLogDTO();
                        string[]      recipients;
                        if (item.GroupId == null) // To check wheather the user sending Group message
                        {
                            recipients = item.RecipientsNumber.ToString().Split(',');
                        }
                        else
                        {
                            recipients = item.RecipientsNumber.ToString().Split(',');
                        }
                        if (recipients.Length == 0)
                        {
                            //oUcButtonControl.showMessage(frmButtonControl.Messageflag.warningMessage, "Select recipients first.");
                            return;
                        }
                        for (int i = 0; i < recipients.Length; i++)                                          // Loop through each recipient number & remove duplicate numbers
                        {
                            if (!string.IsNullOrEmpty(recipients[i].ToString()))                             // Don`t allow empty number
                            {
                                string mobileNumber = GetValidMobileNumber(recipients[i].ToString().Trim()); // Get only digits from Mobile number
                                if (mobileNumber.Length >= MOBILENUMBERLEN)                                  // Check for valid mobile number
                                {
                                    mobileNumber = mobileNumber.Substring(mobileNumber.Length - MOBILENUMBERLEN);
                                    if (!recipientsnumbers.Contains(mobileNumber)) // Check for number duplication.
                                    {
                                        recipientsnumbers.Add(mobileNumber);
                                        recipientnumberslist.Append(mobileNumber).Append(',');
                                    }
                                }
                            }
                        }
                        if (recipientnumberslist.Length != 0)
                        {
                            oMessageLog.Recipients = recipientnumberslist.ToString().Substring(0, recipientnumberslist.Length - 1);
                        }

                        MsgInformationDTO _oMsginfo = new MsgInformationDTO();

                        _oMsginfo.CampaignId = item.Id;// regInfoDT.Rows[0]["SerialKey"].ToString();
                        //xmlpacket += "<cdkey>" + regInfoDT.Rows[0]["SerialKey"].ToString() + "</cdkey>";
                        xmlpacket         += "<campaignId>" + _oMsginfo.CampaignId + "</campaignId>";
                        _oMsginfo.ClientId = item.ClientId;// MachineID.Value();
                        //xmlpacket += "<machineid>" + _oMsginfo.MachineID + "</machineid>";
                        xmlpacket += "<clientId>" + _oMsginfo.ClientId + "</clientId>";

                        if (!string.IsNullOrEmpty(item.Name)) // check for TemplateName
                        {
                            //xmlpacket += "<campaignname>" + MsgCorrect(lkupTemplate.Text) + "</campaignname>";
                            xmlpacket += "<campaignname>" + MsgCorrect(item.Name.ToString()) + "</campaignname>";
                            oMessageLog.MessageTemplateID = _oMsginfo.CampaignId;
                        }
                        else
                        {
                            xmlpacket += "<campaignname>Direct_Message</campaignname>";
                            oMessageLog.MessageTemplateID = _oMsginfo.CampaignId;
                        }

                        if (!string.IsNullOrEmpty(item.GroupId.ToString())) //nameOfGroupForMsgSending
                        {
                            GroupDTO GroupDTO = new GroupDTO();
                            GroupDTO   = GroupService.GetById(Convert.ToInt32(item.GroupId));
                            xmlpacket += "<groupname>" + MsgCorrect(GroupDTO.Name) + "</groupname>"; // nameOfGroupForMsgSending
                            oMessageLog.RecipientType = GroupDTO.Name;
                        }
                        else if (!string.IsNullOrEmpty(item.Name)) //nameOfImportedFile // Check for is direct message to imported contact
                        {
                            oMessageLog.RecipientType = item.Name; //  nameOfImportedFile ;
                        }
                        else
                        {
                            oMessageLog.RecipientType = "Direct";
                        }

                        oMessageLog.MessageDateTime = Convert.ToString(System.DateTime.Now);
                        xmlpacket += "<senddate>" + System.DateTime.Now.ToString("d/MMM/yyyy") + "</senddate>";

                        if (!string.IsNullOrEmpty(item.ScheduledDate.ToString())) //scheduledDate.Text // check for sheduled Date
                        {
                            DateTime ScheduledDateTime = DateTime.Parse(item.ScheduledDate.ToString());
                            if (item.ScheduledTime == null || item.ScheduledTime == "")
                            {
                                item.ScheduledTime = "12:00 AM";
                            }
                            DateTime ScheduledTime = Convert.ToDateTime(item.ScheduledTime);
                            ScheduledDateTime = ScheduledDateTime.AddHours(ScheduledTime.TimeOfDay.Hours);
                            ScheduledDateTime = ScheduledDateTime.AddMinutes(ScheduledTime.TimeOfDay.Minutes);
                            DateTime ActualScheduleDatetime = Convert.ToDateTime(item.ScheduledDate.ToString("MM/dd/yyyy") + " " + ScheduledDateTime.TimeOfDay);;
                            xmlpacket += "<scheduleddate>" + ActualScheduleDatetime.ToString("dd/MMM/yyyy HH:mm tt") + "</scheduleddate>";
                            oMessageLog.MessageScheduledDateTime = Convert.ToString(ScheduledDateTime);
                        }

                        oMessageLog.MessageText = item.Message.ToString().Replace("'", "''"); //memoMessagetxt.Text.Replace("'", "''");

                        if (FormatMessageText(item.Message))                                  //memoMessagetxt.Text
                        {
                            ismailmarge = true;
                            xmlpacket  += "<messagetype>MAILMERGE</messagetype>";
                            oMessageLog.MessageTemplateType = "MAILMERGE";
                            // Get information of numbers which are in Contact list to foramte mail-marge-message
                            string nameOfGroupForMsgSending = null;



                            if (nameOfGroupForMsgSending == null)
                            {
                                dtContact = CommonService.SelectContatsInNumber(recipientnumberslist.ToString().Substring(0, recipientnumberslist.Length - 1), item.ClientId);
                            }
                            else
                            {
                                dtContact = CommonService.SelectContatsInNumber(recipientnumberslist.ToString().Substring(0, recipientnumberslist.Length - 1), item.ClientId);
                            }
                        }
                        else
                        {
                            xmlpacket += "<messagetype>NORMAL</messagetype>";
                            oMessageLog.MessageTemplateType = "NORMAL";
                        }

                        oMessageLog.Count = recipientsnumbers.Count;
                        xmlpacket        += "<messagecount>" + recipientsnumbers.Count.ToString() + "</messagecount>";

                        //oMessageLog.SenderNumber = lookUpSender.Text;
                        List <UserDTO> UserDTOList = new List <UserDTO>();
                        UserDTOList = UserService.GetUsersbyClientId(ClientDTO.Id, "");
                        if (UserDTOList.Count != 0)
                        {
                            foreach (var itemuser in UserDTOList)
                            {
                                if (itemuser.UserType == "Admin")
                                {
                                    oMessageLog.SenderNumber = itemuser.Mobile;
                                    xmlpacket += "<sender>" + MsgCorrect(oMessageLog.SenderNumber) + "</sender>";
                                }
                            }
                        }



                        xmlpacket += "<numbers>";
                        if (ismailmarge)
                        {
                            requiredCreditTosendmsg = AddMsgRecipToXmlpacketMailMerge(item.Message, recipientsnumbers, dtContact.DefaultView, xmlpacket, _oMsginfo, recipientsnumbers.Count);
                        }
                        else
                        {
                            requiredCreditTosendmsg = AddMsgRecipToXmlpacket(item.Message, recipientsnumbers, xmlpacket, _oMsginfo, recipientsnumbers.Count) * recipientsnumbers.Count;
                        }

                        //xmlpacket += "</numbers>";
                        //xmlpacket += "</packet>";
                        //_oMsginfo.xmlpacket = xmlpacket;
                        //_oMsginfo.RequiredCredits = requiredCreditTosendmsg;
                        //Byte[] array = Serializeobject(_oMsginfo);
                        //Byte[] checksum = new MD5CryptoServiceProvider().ComputeHash(array); // calculate checksum for validation

                        //if (requiredCreditTosendmsg > recipientsnumbers.Count)
                        //{
                        //    //DialogResult dlg = XtraMessageBox.Show("You will be charged " + requiredCreditTosendmsg + " credits to send this message." + "\r\n" + "Do you want to send ?", "Conformation", MessageBoxButtons.YesNo);
                        //    //if (dlg == DialogResult.Yes)
                        //    //{

                        //    string responsefromService = SendMessage(array, checksum);
                        //    Response(responsefromService);

                        //    //}
                        //    //else
                        //    //{
                        //    //oUcButtonControl.ShowSend = true;
                        //    //oUcButtonControl.showMessage(frmButtonControl.Messageflag.none, "");
                        //    //oUcButtonControl.ButtonView();
                        //    //this.Update();
                        //    //}
                        //}
                        //else
                        //{
                        //    string responsefromService = SendMessage(array, checksum);
                        //    Response(responsefromService);
                        //}
                    }
                }
            }
            catch (WebException ex)
            {
                //oUcButtonControl.showMessage(frmButtonControl.Messageflag.errorMessage, Global.DisplayConnectionError(ex));
                throw;
            }
        }
        public static string SendMessage(Byte[] array, Byte[] checksum)
        {
            try
            {
                //Checking for Data Accuracy
                Byte[] newchecksum = new MD5CryptoServiceProvider().ComputeHash(array);
                if (checksum.Length == newchecksum.Length)
                {
                    int arraylength = 0;
                    while ((arraylength < checksum.Length) && (newchecksum[arraylength] == checksum[arraylength]))
                    {
                        arraylength++;
                    }
                    if (arraylength != newchecksum.Length)
                    {
                        return(ErrorFlag.DataCorrupted.ToString());
                    }
                }


                // Checking User's Validation that is CDKey & MachineID
                XmlSerializer     xs                 = new XmlSerializer(typeof(MsgInformationDTO));
                MemoryStream      msgStream          = new MemoryStream(array);
                MsgInformationDTO oMsgInformationDTO = (MsgInformationDTO)xs.Deserialize(msgStream);

                CampaignDTO CampaignDTO = new CampaignDTO();
                CampaignDTO = CampaignService.GetById(oMsgInformationDTO.CampaignId);
                //CampaignDTO.ClientId = oMsgInformationDTO.ClientId;
                //CampaignDTO.Id = oMsgInformationDTO.CampaignId;
                ClientDTO ClientDTO = new ClientDTO();
                ClientDTO = ClientService.GetById(CampaignDTO.ClientId);


                string packet = oMsgInformationDTO.xmlpacket;
                string fname  = null;
                if (ValidatePacketAgainstSchema(packet)) // Check xml file validation.
                {
                    if (AllowToProcessClient(CampaignDTO))
                    {
                        DateTime   DateAndTime = System.DateTime.Now;
                        SettingDTO SettingDTO  = new SettingDTO(); // Get limit on msg size
                        SettingDTO = SettingService.GetById(1);

                        int         requiredCredit = 0;
                        XmlDocument x = new XmlDocument();
                        x.LoadXml(packet);
                        XmlNodeList messages = x.SelectNodes("/packet/numbers/message/text()"); // Get all messages from xmlpacket
                        XmlNodeList numbers  = x.SelectNodes("/packet/numbers/number");
                        for (int i = 0; i < messages.Count; i++)                                // Get required credits to send this packet;
                        {
                            requiredCredit += MessageCount(MsgCorrect(messages[i].InnerText.TrimEnd()));
                        }
                        if (messages.Count == 1) // Means one message to all numbers
                        {
                            requiredCredit = requiredCredit * numbers.Count;
                        }

                        if (ClientDTO.SMSCredit >= requiredCredit)
                        {
                            XmlNode    root            = x.DocumentElement;
                            XmlElement requiredcredits = x.CreateElement("requiredcredits");
                            requiredcredits.InnerText = requiredCredit.ToString();
                            root.InsertBefore(requiredcredits, root.LastChild);
                            //_oClsClients.SMSCredits -= requiredCredit;
                            try
                            {
                                fname = DateAndTime.Year.ToString() + DateAndTime.Month + DateAndTime.Day + "-" + DateAndTime.Hour + DateAndTime.Minute + DateAndTime.Second + "-" + oMsgInformationDTO.CampaignId + "-Q.xml";
                                x.Save(ConfigurationManager.AppSettings["SMSFolderPath"].ToString() + fname);
                                x = null;
                                //dbClients.ReduceSMSCredits(oClient, requiredCredit);


                                CampaignDTO CampaignDTONew = new CampaignDTO();
                                CampaignDTONew = CampaignDTO;
                                //CampaignDTONew.IsSent = true;
                                CampaignDTONew.Status = "Sent";
                                CampaignService.Edit(CampaignDTONew);

                                ClientDTO ClientDTOUpdate = new ClientDTO();
                                ClientDTOUpdate           = ClientDTO;
                                ClientDTOUpdate.SMSCredit = ClientDTOUpdate.SMSCredit - requiredCredit;
                                ClientService.Edit(ClientDTOUpdate);
                            }
                            catch (Exception ex)
                            {
                                return(ErrorFlag.FailedToWriteData.ToString());      // Returns "FailedToWriteData" enum name if message file not created
                            }
                            //return ErrorFlag.Success.ToString();                // Return "Success" enum name if Message file created in the SMSQueue folder successfully
                            return(fname);
                        }
                        else
                        {
                            return(ErrorFlag.InsufficientCredits.ToString());  // Returns "InsufficientCredits" enum name if SMSCredits are insufficient for sending message
                        }
                    }
                    else
                    {
                        return(ErrorFlag.InvalidUser.ToString());        // Returns "InvalidUser" enum name if the CDKey or MachineID not matching
                    }
                }
                else
                {
                    return(ErrorFlag.BadXml.ToString()); // Return BAD XmlPacke Error
                }
            }
            catch
            {
                throw;             // Returns error flag name if there are any web exception
            }
        }