Beispiel #1
0
        public HttpResponseMessage CreateRegistration(RegistrationModel registrationModel)
        {
            ResponseModel _response = new ResponseModel();
            var           _getUser  = _userMaster.FindBy(x => x.UserId == registrationModel.UserId).FirstOrDefault();

            if (_getUser == null)
            {
                _response.Type    = "error";
                _response.Message = "User not Exist";
                return(Request.CreateResponse(HttpStatusCode.OK, _response));
            }
            var _getDetail = _registrationRepository.FindBy(x => x.UserId == registrationModel.UserId).FirstOrDefault();

            if (_getDetail != null)
            {
                _response.Type    = "error";
                _response.Message = "Profile already Created";
                return(Request.CreateResponse(HttpStatusCode.OK, _response));
            }

            var model = Mapper.Map <RegistrationModel, Registration>(registrationModel);

            model.CreatedDate = DateTime.Now;
            model.CreatedBy   = registrationModel.CreatedBy;
            model.Status      = (int)Status.InActive;
            model.IsDeleted   = false;
            var Result = _registrationRepository.CreateUserProfile(model);

            if (Result != null)
            {
                // Update UserMaster Status for Inactive
                Usermaster _details = _userMaster.FindBy(x => x.UserId == Result.UserId).FirstOrDefault();
                if (_details != null)
                {
                    _details.Status = (int)Status.InActive;
                    _userMaster.Update(_details);
                    _userMaster.SaveChanges();
                }
                // For Uploading Licence image ----
                foreach (var item in registrationModel.lstDocLicence)
                {
                    if (item != null)
                    {
                        UploadDocumentModel UploadDocument = new UploadDocumentModel();
                        UploadDocument.documents    = new List <DocumentModel>();
                        UploadDocument.ImageSize    = 250;
                        UploadDocument.ImageQuality = 250;
                        UploadDocument.documents.Add(item);
                        List <string> uploadedFileName = SavePicture(UploadDocument);
                        if (uploadedFileName.Count > 0)
                        {
                            LicenceImages licenceImages = new LicenceImages();
                            licenceImages.ImagePath      = uploadedFileName[0].ToString();
                            licenceImages.RegistrationId = Result.RegistrationId;
                            licenceImages.IsActive       = true;
                            _licenceImagesReposiory.Add(licenceImages);
                            _licenceImagesReposiory.SaveChanges();
                        }
                    }
                }

                // For Uploading image ----
                if (registrationModel.DocGSTNo != null)
                {
                    UploadDocumentModel UploadDocumentGSTNo = new UploadDocumentModel();
                    UploadDocumentGSTNo.documents    = new List <DocumentModel>();
                    UploadDocumentGSTNo.ImageSize    = 250;
                    UploadDocumentGSTNo.ImageQuality = 250;
                    UploadDocumentGSTNo.documents.Add(registrationModel.DocGSTNo);
                    List <string> uploadedFileName = SavePicture(UploadDocumentGSTNo);
                    if (uploadedFileName.Count > 0)
                    {
                        Registration _registration = _registrationRepository.FindBy(x => x.RegistrationId == Result.RegistrationId).FirstOrDefault();
                        if (_registration != null)
                        {
                            _registration.GSTNoImage = uploadedFileName[0].ToString();
                            _registrationRepository.Update(_registration);
                            _registrationRepository.SaveChanges();
                        }
                    }
                }

                _response.Type    = "success";
                _response.Message = "Profile created successfully";
                return(Request.CreateResponse(HttpStatusCode.OK, _response));
            }
            else
            {
                _response.Type    = "error";
                _response.Message = "somehing went wrong";
                return(Request.CreateResponse(HttpStatusCode.OK, _response));
            }
        }