Пример #1
0
        //UPDATE BY ID
        public Result Update(CustomerDataObject customerobj, string apiKey)
        {
            ICustomerDataBase customer   = Toggle();
            Result            result_msg = new Result();

            try
            {
                if (Authenticator.ApiKeyAuthenticator(apiKey) == false)
                {
                    throw new Exception("wrongkey");
                }
                if (Validator.IsValidEmail(customerobj.Emailid) == false)
                {
                    throw new CMSException.FormatException("Not a Valid Email");
                }
                if (Validator.IsValidPhone(customerobj.Phone) == false)
                {
                    throw new CMSException.FormatException("Not a Valid PhoneNumber");
                }
                customerobj.Adminid = int.Parse(apiKey);
                int ResultStatus = customer.UpdateDetails(customerobj);
                if (ResultStatus == 0)
                {
                    result_msg.Status = "Failure";
                    if (customerobj.Id <= 0)
                    {
                        result_msg.Message = "Customer ID Required";
                    }
                    else
                    {
                        result_msg.Message = "No Such Customer Found";
                    }
                }
                else
                {
                    result_msg.Status  = "Success";
                    result_msg.Message = "Data Updated Successfully";
                }
            }
            catch (Exception e)
            {
                if (e.Message.Contains(customerobj.Emailid))
                {
                    DuplicateEmailException dupex = new DuplicateEmailException("Email ID already Taken");
                    throw dupex;
                }
                else if (e.Message.Contains(customerobj.Phone.ToString()))
                {
                    DuplicatePhoneException dupex = new DuplicatePhoneException("Phone Number already Taken");
                    throw dupex;
                }
                else
                {
                    throw e;
                }
            }
            return(result_msg);
        }
Пример #2
0
        public Result Register(UserDataObject userObj)
        {
            try
            {
                UserDataBase User      = new UserDataBase();
                Result       ResultObj = new Result();
                if (Validator.IsValidEmail(userObj.Emailid) == false)
                {
                    throw new CMSException.FormatException("Not a Valid Email");
                }
                if (Validator.IsValidPhone(userObj.Phone) == false)
                {
                    throw new CMSException.FormatException("Not a Valid PhoneNumber");
                }
                if (User.Register(userObj) == 1)
                {
                    ResultObj.Status  = "Success";
                    ResultObj.Message = "Created User Successfully";
                }
                else
                {
                    ResultObj.Status  = "Failure";
                    ResultObj.Message = "Couldnt Create User";
                }
                return(ResultObj);
            }
            catch (Exception e)
            {
                if (e.Message.Contains(userObj.Emailid))
                {
                    DuplicateEmailException Dupex = new DuplicateEmailException("Email ID already Taken");
                    throw Dupex;
                }
                else if (e.Message.Contains(userObj.Phone.ToString()))
                {
                    DuplicatePhoneException Dupex = new DuplicatePhoneException("Phone Number already Taken");
                    throw Dupex;
                }

                else
                {
                    throw e;
                }
            }
        }
Пример #3
0
        //CREATE NEW CUSTOMER
        public Result Create(CustomerDataObject customerobj, string apiKey)
        {
            ICustomerDataBase customer   = Toggle();
            Result            result_msg = new Result();

            try
            {
                if (Authenticator.ApiKeyAuthenticator(apiKey) == false)
                {
                    throw new Exception("wrongkey");
                }
                customerobj.Adminid = int.Parse(apiKey);

                int ResultStatus = customer.SetDetails(customerobj);

                if (ResultStatus == 0)
                {
                    result_msg.Status = "Failure";
                }
                else
                {
                    result_msg.Status  = "Success";
                    result_msg.Message = "New Customer Created Successfully";
                }
            }
            catch (Exception e)
            {
                if (e.Message.Contains(customerobj.Emailid))
                {
                    DuplicateEmailException dupex = new DuplicateEmailException("Email ID already Taken");
                    throw dupex;
                }
                else if (e.Message.Contains(customerobj.Phone.ToString()))
                {
                    DuplicatePhoneException dupex = new DuplicatePhoneException("Phone Number already Taken");
                    throw dupex;
                }
                else
                {
                    throw e;
                }
            }
            return(result_msg);
        }