Ejemplo n.º 1
0
        public HttpResponseMessage SaveCity([FromBody] CityModel citymodel)
        {
            string CityID = "-1";

            try
            {
                Mapper.CreateMap <CommunicationApp.Models.CityModel, CommunicationApp.Entity.City>();
                CommunicationApp.Entity.City city = Mapper.Map <CommunicationApp.Models.CityModel, CommunicationApp.Entity.City>(citymodel);

                if (citymodel.CityID <= 0) //new
                {
                    //Insert the city
                    _cityservice.InsertCity(city);     //Save Operation
                    //End : Insert the Customer
                }
                else
                {
                    _cityservice.UpdateCity(city);     //Update Operation
                }
                CityID = city.CityID.ToString();

                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", CityID), Configuration.Formatters.JsonFormatter));
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.NotImplemented, CommonCls.CreateMessage("error", CityID), Configuration.Formatters.JsonFormatter));
            }
        }
Ejemplo n.º 2
0
        public HttpResponseMessage GetCreditCustomerId([FromUri] int CustomerId)
        {
            try
            {
                var models   = new List <CreditResponseModel>();
                var customer = _CustomerService.GetCustomer(CustomerId);
                if (customer == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer not found."), Configuration.Formatters.JsonFormatter));
                }
                var Credits = _CreditService.GetCredits().Where(l => l.CustomerId == CustomerId).ToList();
                if (Credits.Count() > 0)
                {
                    foreach (var Credit in Credits)
                    {
                        Mapper.CreateMap <Friendlier.Entity.Credit, Friendlier.Models.CreditResponseModel>();
                        CreditResponseModel CreditResponseModel = Mapper.Map <Friendlier.Entity.Credit, Friendlier.Models.CreditResponseModel>(Credit);

                        models.Add(CreditResponseModel);
                    }
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", models), Configuration.Formatters.JsonFormatter));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Credit not found."), Configuration.Formatters.JsonFormatter));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "User not found."), Configuration.Formatters.JsonFormatter));
            }
        }
Ejemplo n.º 3
0
 public HttpResponseMessage GetAttendenceSummary([FromUri] int CustomerId)
 {
     try
     {
         if (CustomerId == 0)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer Id is blank."), Configuration.Formatters.JsonFormatter));
         }
         var attendences = _AttendenceService.GetAttendences().Where(a => a.CustomerId == CustomerId).ToList();
         if (attendences.Count() > 0)
         {
             var models = new List <AttendenceModel>();
             Mapper.CreateMap <Onlo.Entity.Attendence, Onlo.Models.AttendenceModel>();
             foreach (var attendence in attendences)
             {
                 Onlo.Models.AttendenceModel Attendence = Mapper.Map <Onlo.Entity.Attendence, Onlo.Models.AttendenceModel>(attendence);
                 models.Add(Attendence);
             }
             return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", models), Configuration.Formatters.JsonFormatter));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", "No attendence found."), Configuration.Formatters.JsonFormatter));
         }
     }
     catch (Exception ex)
     {
         string ErrorMsg = ex.Message.ToString();
         ErrorLogging.LogError(ex);
         return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try again."), Configuration.Formatters.JsonFormatter));
     }
 }
        public HttpResponseMessage GetAllCategory(int CategoryId)
        {
            try
            {
                Mapper.CreateMap <CommunicationApp.Entity.SubCategory, CommunicationApp.Models.SubCategoryModel>();
                var Subcategories = _SubCategoryService.GetSubCategories().Where(c => c.CategoryId == CategoryId).OrderBy(c => c.SubCategoryName);
                List <SubCategoryModel> SubCategoryModelList = new List <SubCategoryModel>();
                foreach (var subcategory in Subcategories)
                {
                    var Suppliers = _SupplierService.GetSuppliers();

                    if (subcategory.CategoryId != 0)
                    {
                        Suppliers = Suppliers.Where(c => c.SubCategoryId == subcategory.SubCategoryId).ToList();
                    }
                    subcategory.SubCategoryName = subcategory.SubCategoryName + "(" + Suppliers.Count + ")";
                    SubCategoryModelList.Add(Mapper.Map <CommunicationApp.Entity.SubCategory, CommunicationApp.Models.SubCategoryModel>(subcategory));
                }
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", SubCategoryModelList), Configuration.Formatters.JsonFormatter));
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "No record found."), Configuration.Formatters.JsonFormatter));
            }
        }
Ejemplo n.º 5
0
        public JsonReturnModel getAttendence(StudentAttendence StudentAttendence)
        {
            List <AttendenceModel> attendenceList = new List <AttendenceModel>();
            var Customer = _CustomerService.GetCustomer(StudentAttendence.CustomerId).CustomerType;

            if (Customer != null)
            {
                if (Customer == StudentAttendence.CustomerType)
                {
                    if (Customer == EnumValue.GetEnumDescription(EnumValue.CustomerType.Student) || Customer == EnumValue.GetEnumDescription(EnumValue.CustomerType.Parent))
                    {
                        var attendences = _AttendenceService.GetAttendences().Where(a => (a.AttendenceDate >= StudentAttendence.StartDate && a.AttendenceDate <= StudentAttendence.EndDate) && a.CustomerId == StudentAttendence.CustomerId).ToList();
                        if (attendences.Count() > 0)
                        {
                            foreach (var item in attendences)
                            {
                                if (item.Status == EnumValue.GetEnumDescription(EnumValue.AttendenceStatus.Present))
                                {
                                    Mapper.CreateMap <Onlo.Entity.Attendence, Onlo.Models.AttendenceModel>();
                                    Onlo.Models.AttendenceModel Attendence = Mapper.Map <Onlo.Entity.Attendence, Onlo.Models.AttendenceModel>(item);
                                    attendenceList.Add(Attendence);
                                }
                            }
                        }
                    }
                    else
                    {
                        var CustomerList = _CustomerService.GetCustomers().Where(c => c.ParentId == StudentAttendence.CustomerId).ToList();
                        if (CustomerList.Count() > 0)
                        {
                            var CustomerIds = CustomerList.Select(s => s.CustomerId).ToList();
                            foreach (var CustomerId in CustomerIds)
                            {
                                var studentAttendence = _AttendenceService.GetAttendences().Where(a => a.CustomerId == CustomerId && a.AttendenceDate == StudentAttendence.StartDate).FirstOrDefault();
                                if (studentAttendence != null)
                                {
                                    Mapper.CreateMap <Onlo.Entity.Attendence, Onlo.Models.AttendenceModel>();
                                    Onlo.Models.AttendenceModel Attendence = Mapper.Map <Onlo.Entity.Attendence, Onlo.Models.AttendenceModel>(studentAttendence);
                                    var studentDetail = _CustomerService.GetCustomer(studentAttendence.CustomerId);
                                    Attendence.StudentName = studentDetail.Name;
                                    Attendence.StudentCode = studentDetail.StudentCode;
                                    Attendence.ProfilePath = studentDetail.PhotoPath;
                                    Attendence.EmailId     = studentDetail.EmailId;
                                    attendenceList.Add(Attendence);
                                }
                            }
                        }
                    }
                    return(CommonCls.CreateMessage("success", attendenceList));
                }
                else
                {
                    return(CommonCls.CreateMessage("error", "This Customer doesnot exist in this customer type."));
                }
            }
            else
            {
                return(CommonCls.CreateMessage("success", "No attendence found."));
            }
        }
        public HttpResponseMessage GetAllStates([FromUri] int CountryId)
        {
            if (CountryId == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Country id is blank."), Configuration.Formatters.JsonFormatter));
            }
            var country = _CountryService.GetCountry(CountryId);

            if (country == null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Wrong counrty id."), Configuration.Formatters.JsonFormatter));
            }
            var states = _StateService.GetStates().Where(s => s.CountryID == CountryId);

            if (states != null)
            {
                var models = new List <StateModel>();
                Mapper.CreateMap <Friendlier.Entity.State, Friendlier.Models.StateModel>();
                foreach (var state in states)
                {
                    models.Add(Mapper.Map <Friendlier.Entity.State, Friendlier.Models.StateModel>(state));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", models), Configuration.Formatters.JsonFormatter));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "No state found."), Configuration.Formatters.JsonFormatter));
            }
        }
        public HttpResponseMessage GetAllCities([FromUri] int StateId)
        {
            if (StateId == 0)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "State id is blank."), Configuration.Formatters.JsonFormatter));
            }
            var State = _StateService.GetState(StateId);

            if (State == null)
            {
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Wrong State id."), Configuration.Formatters.JsonFormatter));
            }
            var cities = _CityService.GetCities().Where(s => s.StateID == StateId);

            if (cities != null)
            {
                var models = new List <CityResponseModel>();
                Mapper.CreateMap <Friendlier.Entity.City, Friendlier.Models.CityResponseModel>();
                foreach (var city in cities)
                {
                    models.Add(Mapper.Map <Friendlier.Entity.City, Friendlier.Models.CityResponseModel>(city));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", models), Configuration.Formatters.JsonFormatter));
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "No city found."), Configuration.Formatters.JsonFormatter));
            }
        }
Ejemplo n.º 8
0
        public HttpResponseMessage SaveForm([FromBody] FormModel formmodel)
        {
            string FormID = "-1";

            try
            {
                Mapper.CreateMap <CommunicationApp.Models.FormModel, CommunicationApp.Entity.Form>();
                CommunicationApp.Entity.Form form = Mapper.Map <CommunicationApp.Models.FormModel, CommunicationApp.Entity.Form>(formmodel);

                if (form.FormId <= 0) //new
                {
                    //Insert the Country
                    _formservice.InsertForm(form); //Save Operation
                    //End : Insert the Customer
                }
                else
                {
                    _formservice.UpdateForm(form); //Update Operation
                }
                FormID = form.FormId.ToString();

                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", FormID), Configuration.Formatters.JsonFormatter));
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", FormID), Configuration.Formatters.JsonFormatter));
            }
        }
        public HttpResponseMessage SaveState([FromBody] StateModel statemodel)
        {
            string StateID = "-1";

            try
            {
                Mapper.CreateMap <CommunicationApp.Models.StateModel, CommunicationApp.Entity.State>();
                CommunicationApp.Entity.State state = Mapper.Map <CommunicationApp.Models.StateModel, CommunicationApp.Entity.State>(statemodel);

                if (state.StateID <= 0) //new
                {
                    //Insert the city
                    _stateservice.InsertState(state); //Save Operation
                    //End : Insert the Customer
                }
                else
                {
                    _stateservice.UpdateState(state); //Update Operation
                }
                StateID = state.StateID.ToString();

                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", StateID), Configuration.Formatters.JsonFormatter));
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", StateID), Configuration.Formatters.JsonFormatter));
            }
        }
Ejemplo n.º 10
0
        public HttpResponseMessage SaveroleDetail([FromBody] RoleDetailModel roledetailmodel)
        {
            string RoleDetailID = "-1";

            try
            {
                Mapper.CreateMap <CommunicationApp.Models.RoleDetailModel, CommunicationApp.Entity.RoleDetail>();
                CommunicationApp.Entity.RoleDetail roledetail = Mapper.Map <CommunicationApp.Models.RoleDetailModel, CommunicationApp.Entity.RoleDetail>(roledetailmodel);

                if (roledetail.RoleDetailID <= 0) //new
                {
                    //Insert the Country
                    _roledetailservice.InsertRoleDetail(roledetail); //Save Operation
                    //End : Insert the Customer
                }
                else
                {
                    _roledetailservice.UpdateRoleDetail(roledetail);     //Update Operation
                }
                RoleDetailID = roledetail.FormId.ToString();

                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", RoleDetailID), Configuration.Formatters.JsonFormatter));
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", RoleDetailID), Configuration.Formatters.JsonFormatter));
            }
        }
Ejemplo n.º 11
0
        public HttpResponseMessage SaveUserRole([FromBody] UserRoleModel userrolemodel)
        {
            string UserRoleID = "-1";

            try
            {
                Mapper.CreateMap <CommunicationApp.Models.UserRoleModel, CommunicationApp.Entity.UserRole>();
                CommunicationApp.Entity.UserRole Userrole = Mapper.Map <CommunicationApp.Models.UserRoleModel, CommunicationApp.Entity.UserRole>(userrolemodel);

                if (Userrole.UserRoleId <= 0) //new
                {
                    //Insert the Country
                    _UserRoleservice.InsertUserRole(Userrole); //Save Operation
                    //End : Insert the Customer
                }
                else
                {
                    _UserRoleservice.UpdateUserRole(Userrole); //Update Operation
                }
                UserRoleID = Userrole.UserRoleId.ToString();

                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", UserRoleID), Configuration.Formatters.JsonFormatter));
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", UserRoleID), Configuration.Formatters.JsonFormatter));
            }
        }
 public HttpResponseMessage GetLocationByID([FromUri] int LocationId, [FromUri] int CustomerId)
 {
     try
     {
         var customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == CustomerId && c.IsActive == true).FirstOrDefault();
         if (customer == null)
         {
             return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer not found."), Configuration.Formatters.JsonFormatter));
         }
         List <string> LocationImages = new List <string>();
         var           Location       = _LocationService.GetLocation(LocationId);
         if (Location != null)
         {
             Mapper.CreateMap <Friendlier.Entity.Location, Friendlier.Models.LocationResponseModel>();
             LocationResponseModel LocationResponseModel = Mapper.Map <Friendlier.Entity.Location, Friendlier.Models.LocationResponseModel>(Location);
             //LocationResponseModel.ContactInfo = Location.MobileNo + "|" + Location.EmailId;
             var images = _LocationImagesService.GetLocationImages().Where(l => l.LocationId == LocationId).ToList();
             if (images.Count() > 0)
             {
                 foreach (var image in images)
                 {
                     LocationImages.Add(image.ImagePath);
                 }
             }
             // LocationResponseModel.ContactInfo = Location.MobileNo + "|" + Location.EmailId;
             LocationResponseModel.LocationImages = LocationImages;
             var tags = _LocationTagService.GetLocationTags().Where(t => t.LocationId == LocationId).Select(t => t.Tag).ToList();
             if (tags.Count() > 0)
             {
                 string tagList = "";
                 foreach (var tag in tags)
                 {
                     tagList = tagList + "," + tag;
                 }
                 LocationResponseModel.Tags = tagList.TrimEnd(',').TrimStart(',');
             }
             var isFavourite = _FavoriteService.GetFavorites().Where(f => f.LocationId == LocationId && f.CustomerId == CustomerId).FirstOrDefault();
             if (isFavourite == null)
             {
                 LocationResponseModel.IsFavourite = false;
             }
             else
             {
                 LocationResponseModel.IsFavourite = true;
             }
             return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", LocationResponseModel), Configuration.Formatters.JsonFormatter));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Location not found."), Configuration.Formatters.JsonFormatter));
         }
     }
     catch (Exception ex)
     {
         string ErrorMsg = ex.Message.ToString();
         ErrorLogging.LogError(ex);
         return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "User not found."), Configuration.Formatters.JsonFormatter));
     }
 }
Ejemplo n.º 13
0
        public HttpResponseMessage DeleteFavorite([FromBody] deleteFavoriteModel deleteFavoriteModel)
        {
            try
            {
                if (deleteFavoriteModel.CustomerId == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer Id is blank."), Configuration.Formatters.JsonFormatter));
                }
                if (deleteFavoriteModel.FavoriteIds == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Favorite Ids are blank."), Configuration.Formatters.JsonFormatter));
                }
                var models   = new List <FavoriteResponseModel>();
                var customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == deleteFavoriteModel.CustomerId && c.IsActive == true);
                if (customer == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer not found."), Configuration.Formatters.JsonFormatter));
                }


                var favoriteList = _FavoriteService.GetFavorites().Where(f => f.CustomerId == deleteFavoriteModel.CustomerId).ToList();
                if (favoriteList != null)
                {
                    string[] favIds = deleteFavoriteModel.FavoriteIds.Split(',');
                    // List<int> favoriteListIds = favoriteList.Select(f => f.FavoriteId).ToList();
                    // List<int> common = favoriteListIds.Intersect(deleteFavoriteModel.FavoriteIds).ToList();
                    // if (common.Count == deleteFavoriteModel.FavoriteIds.Count())
                    //// if (favoriteListIds.Intersect(deleteFavoriteModel.FavoriteIds).Any())
                    // {
                    foreach (var id in favIds)
                    {
                        var deleteFav = _FavoriteService.GetFavorite(Convert.ToInt32(id));
                        if (deleteFav != null)
                        {
                            _FavoriteService.DeleteFavorite(deleteFav);
                        }
                    }
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", "Successfully deleted."), Configuration.Formatters.JsonFormatter));
                    //}
                    //else
                    //{
                    //    return Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Wrong favorite id."), Configuration.Formatters.JsonFormatter);
                    //}
                }


                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Favourite not found."), Configuration.Formatters.JsonFormatter));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "User not found."), Configuration.Formatters.JsonFormatter));
            }
        }
        public HttpResponseMessage GetAllDivision(int CategoryId, int SubCategoryId)
        {
            try
            {
                var Regions = _DivisionService.GetDivisions().Where(c => c.ParentId == null).OrderBy(c => c.DivisionName);
                List <DivisionModel> RegionModelList = new List <DivisionModel>();
                Mapper.CreateMap <CommunicationApp.Entity.Division, CommunicationApp.Models.DivisionModel>();
                foreach (var Region in Regions)
                {
                    var Suppliers = _SupplierService.GetSuppliers();

                    if (CategoryId != 0)
                    {
                        Suppliers = Suppliers.Where(c => c.CategoryId == CategoryId).ToList();
                    }
                    if (SubCategoryId != 0)
                    {
                        Suppliers = Suppliers.Where(c => c.SubCategoryId == SubCategoryId).ToList();
                    }
                    if (Region.DivisionId != 0)
                    {
                        //Suppliers = Suppliers.Where(c => c.Region.Contains(Region.DivisionId.ToString())).ToList();
                        Suppliers = Suppliers.Where(c => c.Region == Region.DivisionId.ToString()).ToList();
                    }
                    Region.DivisionName = Region.DivisionName + "(" + Suppliers.Count + ")";

                    var SubRegions = _DivisionService.GetDivisions().Where(c => c.ParentId == Region.DivisionId).OrderBy(c => c.DivisionName);
                    List <DivisionModel> SubRegionModelList = new List <DivisionModel>();
                    foreach (var SubRegion in SubRegions)
                    {
                        var SubRegionSuppliers = _SupplierService.GetSuppliers();
                        if (SubRegion.DivisionId != 0)
                        {
                            SubRegionSuppliers = SubRegionSuppliers.Where(c => c.SubRegion == SubRegion.DivisionId.ToString() && c.CategoryId == CategoryId && c.SubCategoryId == SubCategoryId).ToList();
                        }
                        SubRegion.DivisionName = SubRegion.DivisionName + "(" + SubRegionSuppliers.Count + ")";
                        SubRegionModelList.Add(Mapper.Map <CommunicationApp.Entity.Division, CommunicationApp.Models.DivisionModel>(SubRegion));
                    }

                    var _Regionmodel = Mapper.Map <CommunicationApp.Entity.Division, CommunicationApp.Models.DivisionModel>(Region);
                    _Regionmodel.SubRegionModel = SubRegionModelList;
                    RegionModelList.Add(_Regionmodel);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", RegionModelList), Configuration.Formatters.JsonFormatter));
            }
            catch
            {
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "No record found."), Configuration.Formatters.JsonFormatter));
            }
        }
        public HttpResponseMessage ForgotPassword([FromBody] ForgetPasswordsModel usermodel)
        {
            try
            {
                if (usermodel.CustomerType == "" || usermodel.CustomerType == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer Type is blank."), Configuration.Formatters.JsonFormatter));
                }
                if (usermodel.CustomerType != EnumValue.GetEnumDescription(EnumValue.CustomerType.Customer) && usermodel.CustomerType != EnumValue.GetEnumDescription(EnumValue.CustomerType.ServiceProvider))
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Wrong Customer Type."), Configuration.Formatters.JsonFormatter));
                }
                if (usermodel.EmailId == "" || usermodel.CustomerType == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer Type is blank."), Configuration.Formatters.JsonFormatter));
                }
                var customer = _CustomerService.GetCustomers().Where(x => x.EmailId == usermodel.EmailId && x.CustomerType == usermodel.CustomerType).FirstOrDefault();
                if (customer != null)
                {
                    var user = _UserService.GetUserById(Convert.ToInt32(customer.UserId));
                    if (user != null)
                    {
                        if (!customer.IsActive)
                        {
                            return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "User is deactivated."), Configuration.Formatters.JsonFormatter));
                        }
                        //Send Email to User
                        string Password = SecurityFunction.DecryptString(user.Password);
                        SendMailToUser(customer.FirstName + " " + customer.LastName, usermodel.EmailId, Password);

                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", "Password has been sent to your email. Please check your email."), Configuration.Formatters.JsonFormatter));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "User is not found."), Configuration.Formatters.JsonFormatter));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Incorrect email id."), Configuration.Formatters.JsonFormatter));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try later."), Configuration.Formatters.JsonFormatter));
            }
        }
        public HttpResponseMessage GetProductList([FromUri] int PageNumber)
        {
            try
            {
                //if (ServiceProviderId == 0)
                //{
                //    return Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "ServiceProvider Id is blank"), Configuration.Formatters.JsonFormatter);
                //}

                //var Customer = _CustomerService.GetCustomer(ServiceProviderId);
                //if (Customer != null)
                //{
                //if (Customer.IsActive)
                //{
                var products = _ProductService.GetProducts().ToList();
                if (products.Count() > 0)
                {
                    var list = new List <ProductResponseModel>();
                    foreach (var product in products)
                    {
                        Mapper.CreateMap <Product, ProductResponseModel>();
                        list.Add(Mapper.Map <Product, ProductResponseModel>(product));
                    }
                    int numberOfObjectsPerPage = 10;
                    var modelsdata             = list.Skip(numberOfObjectsPerPage * PageNumber).Take(numberOfObjectsPerPage);
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", modelsdata), Configuration.Formatters.JsonFormatter));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", "no products found."), Configuration.Formatters.JsonFormatter));
                }
                //    }
                //    else
                //    {
                //        return Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "User not found."), Configuration.Formatters.JsonFormatter);
                //    }
                //}
                //else
                //{
                //    return Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "User not found."), Configuration.Formatters.JsonFormatter);
                //}
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Try again later."), Configuration.Formatters.JsonFormatter));
            }
        }
Ejemplo n.º 17
0
        public HttpResponseMessage SaveCredit([FromBody] CreditModel CreditModel)
        {
            try
            {
                if (CreditModel.CustomerId == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer Id is blank"), Configuration.Formatters.JsonFormatter));
                }
                if (CreditModel.Credits == null || CreditModel.Credits == "")
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Credit is blank"), Configuration.Formatters.JsonFormatter));
                }

                var customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == CreditModel.CustomerId).FirstOrDefault();
                if (customer != null)
                {
                    var credits = _CreditService.GetCredits().Where(c => c.CustomerId == CreditModel.CustomerId).FirstOrDefault();
                    if (credits == null)
                    {
                        Mapper.CreateMap <CreditModel, Credit>();
                        var credit = Mapper.Map <CreditModel, Credit>(CreditModel);
                        _CreditService.InsertCredit(credit);
                        Mapper.CreateMap <Credit, CreditResponseModel>();
                        CreditResponseModel CreditResponseModel = Mapper.Map <Credit, CreditResponseModel>(credit);

                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", CreditResponseModel), Configuration.Formatters.JsonFormatter));
                    }
                    else
                    {
                        credits.Credits = (CreditModel.Credits != null || CreditModel.Credits != "")?CreditModel.Credits:credits.Credits;
                        _CreditService.UpdateCredit(credits);
                        Mapper.CreateMap <Credit, CreditResponseModel>();
                        CreditResponseModel CreditResponseModel = Mapper.Map <Credit, CreditResponseModel>(credits);

                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", CreditResponseModel), Configuration.Formatters.JsonFormatter));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer id is wrong."), Configuration.Formatters.JsonFormatter));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try again."), Configuration.Formatters.JsonFormatter));
            }
        }
Ejemplo n.º 18
0
 public HttpResponseMessage DeleteForm(int FormId)
 {
     try
     {
         var form = _formservice.GetForm(FormId);
         _formservice.DeleteForm(form);
         return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", FormId), Configuration.Formatters.JsonFormatter));
     }
     catch (Exception ex)
     {
         string ErrorMsg = ex.Message.ToString();
         ErrorLogging.LogError(ex);
         return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", FormId), Configuration.Formatters.JsonFormatter));
     }
 }
Ejemplo n.º 19
0
 public HttpResponseMessage DeleteRoleDetail(int RoleDetailId)
 {
     try
     {
         var roledetail = _roledetailservice.GetRoleDetail(RoleDetailId);
         _roledetailservice.DeleteRoleDetail(roledetail);
         return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", RoleDetailId), Configuration.Formatters.JsonFormatter));
     }
     catch (Exception ex)
     {
         string ErrorMsg = ex.Message.ToString();
         ErrorLogging.LogError(ex);
         return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", RoleDetailId), Configuration.Formatters.JsonFormatter));
     }
 }
Ejemplo n.º 20
0
 public HttpResponseMessage DeleteUserRole(int UserRoleId)
 {
     try
     {
         var Userrole = _UserRoleservice.GetUserRole(UserRoleId);
         _UserRoleservice.DeleteUserRole(Userrole);
         return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", UserRoleId), Configuration.Formatters.JsonFormatter));
     }
     catch (Exception ex)
     {
         string ErrorMsg = ex.Message.ToString();
         ErrorLogging.LogError(ex);
         return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", UserRoleId), Configuration.Formatters.JsonFormatter));
     }
 }
Ejemplo n.º 21
0
 public HttpResponseMessage DeleteCity(int CityId)
 {
     try
     {
         var city = _cityservice.GetCity(CityId);
         _cityservice.DeleteCity(city);
         return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", CityId), Configuration.Formatters.JsonFormatter));
     }
     catch (Exception ex)
     {
         string ErrorMsg = ex.Message.ToString();
         ErrorLogging.LogError(ex);
         return(Request.CreateResponse(HttpStatusCode.NotImplemented, CommonCls.CreateMessage("error", CityId), Configuration.Formatters.JsonFormatter));
     }
 }
 public HttpResponseMessage ChangePassword([FromBody] ChangePasswordsModel changeModel)
 {
     try
     {
         var customer = _CustomerService.GetCustomers().Where(x => x.CustomerId == changeModel.CustomerId && x.IsActive == true).FirstOrDefault();
         if (customer != null)
         {
             if (customer.Password == "")
             {
                 return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "only manually registered users can change their password."), Configuration.Formatters.JsonFormatter));
             }
             var user = _UserService.GetUserById(Convert.ToInt32(customer.UserId));//(customer.UserId);
             if (user != null)
             {
                 var sp = _AgencyIndividualService.GetAgencyIndividuals().Where(a => a.UserId == Convert.ToInt32(customer.UserId)).FirstOrDefault();
                 if (SecurityFunction.DecryptString(user.Password) == changeModel.OldPassword)
                 {
                     sp.Password = customer.Password = user.Password = SecurityFunction.EncryptString(changeModel.NewPassword);
                     _UserService.UpdateUser(user);
                     _CustomerService.UpdateCustomer(customer);
                     _AgencyIndividualService.UpdateAgencyIndividual(sp);
                     return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", "Password changed successfully."), Configuration.Formatters.JsonFormatter));
                 }
                 else
                 {
                     return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Wrong old password."), Configuration.Formatters.JsonFormatter));
                 }
             }
             else
             {
                 return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "User does not exist."), Configuration.Formatters.JsonFormatter));
             }
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "User does not exist."), Configuration.Formatters.JsonFormatter));
         }
     }
     catch (Exception ex)
     {
         string ErrorMsg = ex.Message.ToString();
         ErrorLogging.LogError(ex);
         return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try later."), Configuration.Formatters.JsonFormatter));
     }
 }
        public HttpResponseMessage SavePurchasedLocation([FromBody] LocationModel LocationModel)
        {
            try
            {
                if (LocationModel.CustomerId == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer Id is blank"), Configuration.Formatters.JsonFormatter));
                }
                if (LocationModel.LocationId == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Location Id is blank"), Configuration.Formatters.JsonFormatter));
                }

                var customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == LocationModel.CustomerId && c.IsActive == true).FirstOrDefault();
                if (customer != null)
                {
                    var location = _LocationService.GetLocations().Where(l => l.LocationId == LocationModel.LocationId).FirstOrDefault();
                    if (location != null)
                    {
                        location.IsPurchased   = true;
                        location.PurchasedById = LocationModel.CustomerId;
                        _LocationService.UpdateLocation(location);
                        //Mapper.CreateMap<Location, LocationResponseModel>();
                        //LocationResponseModel LocationResponseModel = Mapper.Map<Location, LocationResponseModel>(location);

                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", "Successfully purchased."), Configuration.Formatters.JsonFormatter));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "No location found."), Configuration.Formatters.JsonFormatter));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer not found."), Configuration.Formatters.JsonFormatter));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try again."), Configuration.Formatters.JsonFormatter));
            }
        }
        public HttpResponseMessage GetRecentChatListByCustomer([FromUri] Guid CustomerId, [FromUri] int PageNumber)
        {
            var models = new List <RecentChatServiceProviderResponseModel>();

            try
            {
                var jobRequests = _RequestService.GetRequests().Where(c => c.CustomerIdBy == CustomerId).Select(c => c.CustomerIdTo).ToList();
                foreach (var jobRequest in jobRequests.Distinct())
                {
                    var user = _CustomerService.GetCustomer(jobRequest);
                    Mapper.CreateMap <Customer, RecentChatServiceProviderResponseModel>();
                    var customer = Mapper.Map <Customer, RecentChatServiceProviderResponseModel>(user);
                    if (customer != null)
                    {
                        var message = _ChatService.GetChats().Where(c => c.CustomerIdBy == jobRequest || c.CustomerIdTo == jobRequest).OrderByDescending(c => c.DateTimeCreated).Take(1).FirstOrDefault();

                        if (message != null)
                        {
                            string sqlFormattedDate = message.DateTimeCreated.HasValue ? message.DateTimeCreated.Value.ToString("yyyy-MM-dd HH:mm:ss.fff") : "";

                            customer.ChatTime = sqlFormattedDate;
                            customer.Message  = message.ChatContent;
                        }
                        else
                        {
                            customer.Message = "";
                        }

                        //customer.CategoryName = _CategoryService.GetCategory(Convert.ToInt32(_CustomerService.GetCustomer(jobRequest).CategoryId)).Name;
                        models.Add(customer);
                    }
                }
                int numberOfObjectsPerPage = 10;
                var modelsdata             = models.Skip(numberOfObjectsPerPage * PageNumber).OrderByDescending(c => c.ChatTime).Take(numberOfObjectsPerPage);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", modelsdata), Configuration.Formatters.JsonFormatter));
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", models), Configuration.Formatters.JsonFormatter));
            }
        }
Ejemplo n.º 25
0
        public HttpResponseMessage SaveFavourite([FromBody] FavoriteModel FavouriteModel)
        {
            try
            {
                if (FavouriteModel.CustomerId == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer Id is blank"), Configuration.Formatters.JsonFormatter));
                }

                if (FavouriteModel.LocationId == 0)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Location Id is blank"), Configuration.Formatters.JsonFormatter));
                }
                var customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == FavouriteModel.CustomerId && c.IsActive == true).FirstOrDefault();
                if (customer != null)
                {
                    var favorite = _FavoriteService.GetFavorites().Where(f => f.CustomerId == FavouriteModel.CustomerId && f.LocationId == FavouriteModel.LocationId).FirstOrDefault();
                    if (favorite != null)
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Already exists."), Configuration.Formatters.JsonFormatter));
                    }
                    Mapper.CreateMap <FavoriteModel, HobbiesAndInterests>();
                    HobbiesAndInterests favorites = Mapper.Map <FavoriteModel, HobbiesAndInterests>(FavouriteModel);
                    _FavoriteService.InsertFavorite(favorites);
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", "Successfully added."), Configuration.Formatters.JsonFormatter));
                }

                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer not found."), Configuration.Formatters.JsonFormatter));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try again."), Configuration.Formatters.JsonFormatter));
            }
        }
        public HttpResponseMessage GetAllCategories()
        {
            try
            {
                var categories = _CategoryService.GetCategories();
                var models     = new List <categoryResponseModule>();
                Mapper.CreateMap <HomeHelp.Entity.Category, HomeHelp.Models.categoryResponseModule>();
                foreach (var category in categories)
                {
                    var categoryModel = Mapper.Map <HomeHelp.Entity.Category, HomeHelp.Models.categoryResponseModule>(category);
                    models.Add(categoryModel);
                }

                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", models), Configuration.Formatters.JsonFormatter));
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Try again."), Configuration.Formatters.JsonFormatter));
            }
        }
Ejemplo n.º 27
0
        public HttpResponseMessage GetAllPackages()
        {
            var models = new List <PackageModel>();

            try
            {
                var Packages = _PackageService.GetPackages();
                Mapper.CreateMap <Friendlier.Entity.Package, Friendlier.Models.PackageModel>();
                foreach (var Package in Packages)
                {
                    Friendlier.Models.PackageModel PackageModel = Mapper.Map <Friendlier.Entity.Package, Friendlier.Models.PackageModel>(Package);
                    models.Add(PackageModel);
                }
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", models), Configuration.Formatters.JsonFormatter));
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", models), Configuration.Formatters.JsonFormatter));
            }
        }
Ejemplo n.º 28
0
        public HttpResponseMessage GetCommentsById([FromUri] int CustomerId, int TaskId, int PageNumber)
        {
            var models = new List <CommentModel>();

            try
            {
                var Comments = _CommentService.GetComments().Where(c => c.TaskId == TaskId).ToList();
                if (Comments.Count() > 0)
                {
                    foreach (var Comment in Comments)
                    {
                        Mapper.CreateMap <Onlo.Entity.Comment, Onlo.Models.CommentModel>();
                        Onlo.Models.CommentModel Model = Mapper.Map <Onlo.Entity.Comment, Onlo.Models.CommentModel>(Comment);
                        var customerDetail             = _CustomerService.GetCustomer(Comment.CustomerId);
                        Model.Name         = customerDetail.Name;
                        Model.PhotoPath    = customerDetail.PhotoPath;
                        Model.CustomerType = customerDetail.CustomerType;
                        models.Add(Model);
                    }
                    var CommentOrderByAsc      = models.OrderByDescending(o => o.CreatedOn).ToList();
                    int numberOfObjectsPerPage = 15;
                    var modelsdata             = CommentOrderByAsc.Skip(numberOfObjectsPerPage * PageNumber).Take(numberOfObjectsPerPage);
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", modelsdata), Configuration.Formatters.JsonFormatter));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Comment not found."), Configuration.Formatters.JsonFormatter));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "User not found."), Configuration.Formatters.JsonFormatter));
            }
        }
        public async Task <HttpResponseMessage> UploadImage()
        {
            // Check if the request contains multipart/form-data.
            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            string root = HttpContext.Current.Server.MapPath("~/IdProof/temp");

            CustomMultipartFormDataStreamProvider1 provider = new CustomMultipartFormDataStreamProvider1(root);

            try
            {
                StringBuilder sb = new StringBuilder();     // Holds the response body

                Type          type = typeof(CustomerModel); // Get type pointer
                CustomerModel locationImagesModel = new CustomerModel();

                // Read the form data and return an async task.
                CustomMultipartFormDataStreamProvider1 x = await Request.Content.ReadAsMultipartAsync(provider);

                Guid CustomerId = new Guid();
                // This illustrates how to get the form data.
                foreach (var key in provider.FormData.AllKeys)
                {
                    if (key == "CustomerId")
                    {
                        string propertyValue = provider.FormData.GetValues(key).FirstOrDefault();
                        if (propertyValue != null)
                        {
                            CustomerId = new Guid(propertyValue);
                            break;
                        }
                    }
                }

                //Delete all already exist files
                HomeHelp.Entity.Customer Customer = _CustomerService.GetCustomers().Where(c => c.CustomerId == CustomerId && c.IsActive == true).FirstOrDefault();
                if (Customer != null)
                {
                    if (Customer.IdProof != "" && Customer.IdProof != null)
                    {
                        DeleteImage(Customer.IdProof);
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "No user found."), Configuration.Formatters.JsonFormatter));
                }

                // Process the list of files found in the directory.
                string[] fileEntries = Directory.GetFiles(root);
                foreach (string fileName in fileEntries)
                {
                    var fileFound = provider.FileData.Where(c => c.Headers.ContentDisposition.FileName.Replace("\"", string.Empty) == Path.GetFileName(fileName)).FirstOrDefault();
                    if (fileFound != null)
                    {
                        //string NewFileName = Guid.NewGuid() + "_Event" + EventId.ToString() + Path.GetExtension(fileName);
                        string NewFileName = Guid.NewGuid() + Path.GetExtension(fileName);

                        string NewRoot = HttpContext.Current.Server.MapPath("~/IdProof") + "\\" + NewFileName;

                        System.IO.File.Move(fileName, NewRoot);

                        string URL = CommonCls.GetURL() + "/IdProof/" + NewFileName;

                        Customer.IdProof = URL;
                        _CustomerService.UpdateCustomer(Customer);
                        sb.Append(URL);
                    }
                }

                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", Customer.IdProof), Configuration.Formatters.JsonFormatter));
            }
            catch (System.Exception e)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e));
            }
        }
        public HttpResponseMessage SaveChat([FromBody] ChatModel chatModel)
        {
            string ChatID = "-1";

            try
            {
                if (chatModel.CustomerIdBy == new Guid())
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "CustomerId By is blank."), Configuration.Formatters.JsonFormatter));
                }
                if (chatModel.CustomerIdTo == new Guid())
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "CustomerId To is blank."), Configuration.Formatters.JsonFormatter));
                }
                var customerTo = _CustomerService.GetCustomer(chatModel.CustomerIdTo);
                if (customerTo == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer To not found."), Configuration.Formatters.JsonFormatter));
                }
                var customerBy = _CustomerService.GetCustomer(chatModel.CustomerIdBy);
                if (customerBy == null)
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Customer By not found."), Configuration.Formatters.JsonFormatter));
                }
                if (chatModel.ChatContent != null && chatModel.ChatContent != "")
                {
                    List <Guid?> ListCustomerIDs = new List <Guid?>();
                    ListCustomerIDs.Add(chatModel.CustomerIdBy);
                    ListCustomerIDs.Add(chatModel.CustomerIdTo);


                    var isFriend = _RequestService.GetRequests().Where(x => ListCustomerIDs.Contains(x.CustomerIdBy) && ListCustomerIDs.Contains(x.CustomerIdTo)).FirstOrDefault();
                    if (isFriend != null)
                    {
                        Mapper.CreateMap <HomeHelp.Models.ChatModel, HomeHelp.Entity.Chat>();
                        HomeHelp.Entity.Chat chat = Mapper.Map <HomeHelp.Models.ChatModel, HomeHelp.Entity.Chat>(chatModel);
                        if (chatModel.ChatId <= 0)
                        {
                            TimeZoneInfo tz = TimeZoneInfo.Local;
                            chat.DateTimeCreated = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now, tz);
                            _ChatService.Insert(chat); //Save Operation
                            ChatID = chat.ChatId.ToString();
                        }

                        // Code For GCM & Iphone
                        //var Customer = _CustomerService.GetCustomer(Convert.ToInt32(chatModel.CustomerIdTo));
                        //if (Customer != null)
                        //{
                        //    var Chats = _ChatService.GetAll().ToList();
                        //    var Results = (from m in Chats
                        //                   where m.CustomerIdTo == chatModel.CustomerIdTo && m.IsRead == false
                        //                   group m by new { m.CustomerIdTo } into g
                        //                   select new
                        //                   {
                        //                       CustomerIdBy = g.Key.CustomerIdTo,
                        //                       ChatContent = (from c in Chats
                        //                                      where c.CustomerIdTo == chatModel.CustomerIdTo && c.IsRead == false
                        //                                      orderby c.DateTimeCreated descending
                        //                                      select c.ChatContent).FirstOrDefault(),
                        //                       Count = g.Count()
                        //                   }).ToList();

                        //    var models = new List<ChatModel>();

                        //    var UserMessage = "";
                        //    bool NotificationStatus = true;
                        //    if (Results.Count() >= 0)
                        //    {
                        //        int MessageCount = Convert.ToInt32(Results.Sum(x => x.Count).ToString()) + 1;
                        string UserMessage = "You have new message.";

                        string NotificationType = "chat";
                        string Flag             = "NewChatMessage";

                        //Save notification in Table
                        Notification Notification = new Notification();
                        Notification.NotificationId = 0; //New Case
                        //Notification.ClientId = _Event.ClientID; Save it as NULL
                        Notification.CustomerIdBy = customerBy.CustomerId;
                        Notification.CustomerIdTo = customerTo.CustomerId;
                        //Notification.EventID = _Event.EventID; Save it as NULL
                        Notification.UserMessage      = UserMessage;
                        Notification.NotificationType = NotificationType;
                        Notification.Flag             = Flag;
                        Notification.DeviceType       = customerBy.DeviceType;
                        _NotificationService.InsertNotification(Notification);
                        //        //End : Save notification in Table

                        // string Message = "{\"flag\":\"" + Flag + "\",\"message\":\"" + UserMessage + "\",\"ChatContent\":\"" + chatModel.ChatContent + "\"}";


                        string Message = "{ \"ChatId\": \"" + ChatID + "\",      \"CustomerIdBy\": \"" + customerBy.CustomerId + "\", \"CustomerIdTo\": \"" + customerTo.CustomerId + "\",      \"ChatContent\": \"" + chatModel.ChatContent
                                         + "\",      \"flag\": \"" + Flag + "\",      \"IsRead\": \"" + chat.IsRead + "\",     \"IsDeletedCustomerBy\":\"" + chat.IsDeletedCustomerBy
                                         + "\",      \"IsDeletedCustomerTo\": \"" + chat.IsDeletedCustomerTo + "\",     \"DateTimeCreated\": \""
                                         + chat.DateTimeCreated + "\",      \"CustomersBy\": { \"CustomerId\": \"" + customerBy.CustomerId
                                         + "\",       \"FirstName\": \"" + customerBy.FirstName + "\",        \"LastName\": \"" + customerBy.LastName
                                         + "\",       \"PhotoPath\": \"" + customerBy.PhotoPath + "\"      }, \"CustomersTo\": { \"CustomerId\": \"" + customerTo.CustomerId + "\",       \"FirstName\": \"" + customerTo.FirstName + "\",      \"LastName\": \"" + customerTo.LastName + "\",       \"PhotoPath\": \"" + customerTo.PhotoPath + "\"     }     }";


                        if (customerTo.ApplicationId != null && customerTo.ApplicationId != "")
                        {
                            if (customerTo.DeviceType == EnumValue.GetEnumDescription(EnumValue.DeviceType.Android))
                            {
                                //Send Notification another Andriod
                                CommonCls.SendFCM_Notifications(customerTo.ApplicationId, Message, true);
                            }
                            else
                            {
                                string Msg = customerTo.FirstName + " " + customerTo.LastName + " : " + chat.ChatContent;

                                CommonCls.TestSendFCM_Notifications(customerTo.ApplicationId, Message, Msg, true);
                                //CommonCls.TestSendFCM_Notifications(customerTo.ApplicationId, Message, true);
                            }
                        }
                        Mapper.CreateMap <HomeHelp.Entity.Chat, HomeHelp.Models.ChatResponseModel>();
                        HomeHelp.Models.ChatResponseModel ChatModel = Mapper.Map <HomeHelp.Entity.Chat, HomeHelp.Models.ChatResponseModel>(chat);
                        string sqlFormattedDate = chat.DateTimeCreated.HasValue ? chat.DateTimeCreated.Value.ToString("yyyy-MM-dd HH:mm:ss.fff") : "";

                        ChatModel.DateTimeCreated = sqlFormattedDate;

                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("success", ChatModel), Configuration.Formatters.JsonFormatter));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "they are not associated."), Configuration.Formatters.JsonFormatter));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Chat content is blank."), Configuration.Formatters.JsonFormatter));
                }
            }
            catch (Exception ex)
            {
                string ErrorMsg = ex.Message.ToString();
                ErrorLogging.LogError(ex);
                return(Request.CreateResponse(HttpStatusCode.OK, CommonCls.CreateMessage("error", "Please try later"), Configuration.Formatters.JsonFormatter));
            }
        }