示例#1
0
        public async Task <GenericResponse <string> > UpdateDobi(Dobi dobi)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(dobi.PassportNumber) && string.IsNullOrWhiteSpace(dobi.IcNumber))
                {
                    return(new GenericResponse <string>(false, null, "Passport or IC number is required"));
                }
                if (string.IsNullOrWhiteSpace(dobi.DobiId))
                {
                    return(new GenericResponse <string>(false, null, "Invalid Dobi."));
                }
                var existingDobi = await _dobiRepository.GetDobiById(dobi.DobiId);

                if (existingDobi == null)
                {
                    return(new GenericResponse <string>(false, null, "Invalid Dobi."));
                }

                if ((existingDobi.Email != dobi.Email) && !await _dobiRepository.IsEmailAvailable(dobi.Email))
                {
                    return(new GenericResponse <string>(false, null, "Email is not available"));
                }
                else if ((existingDobi.Phone != dobi.Phone) && !await _dobiRepository.IsPhoneNumberAvailable(dobi.Phone))
                {
                    return(new GenericResponse <string>(false, null, "Phone number is not available"));
                }
                else if ((existingDobi.PassportNumber != dobi.PassportNumber) && !string.IsNullOrWhiteSpace(dobi.PassportNumber))
                {
                    if (!await _dobiRepository.IsPassportNumberAvailable(dobi.PassportNumber))
                    {
                        return(new GenericResponse <string>(false, null, "Passport number is not available"));
                    }
                }
                else if ((existingDobi.IcNumber != dobi.IcNumber) && !string.IsNullOrWhiteSpace(dobi.PassportNumber))
                {
                    if (!await _dobiRepository.IsIcNumberAvailable(dobi.IcNumber))
                    {
                        return(new GenericResponse <string>(false, null, "IC number is not available"));
                    }
                }
                else if ((existingDobi.DrivingLicense != dobi.DrivingLicense) && !string.IsNullOrWhiteSpace(dobi.DrivingLicense) && !await _dobiRepository.IsDrivingLicenseAvailable(dobi.DrivingLicense))
                {
                    return(new GenericResponse <string>(false, null, "Driving license is not available"));
                }
                var response = await _dobiRepository.UpdateDobi(dobi);

                if (response == null)
                {
                    return(new GenericResponse <string>(false, null, "Error updating Dobi."));
                }
                return(new GenericResponse <string>(true, null, "Dobi updated successfully."));
            }
            catch (Exception exception)
            {
                throw new Exception("Error updating dobi" + exception);
            }
        }
示例#2
0
        public async Task <GenericResponse <string> > AddDobi(Dobi dobi)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(dobi.PassportNumber) && string.IsNullOrWhiteSpace(dobi.IcNumber))
                {
                    return(new GenericResponse <string>(false, null, "Passport or IC number is required"));
                }
                if (!await _dobiRepository.IsEmailAvailable(dobi.Email))
                {
                    return(new GenericResponse <string>(false, null, "Email is not available"));
                }
                else if (!await _dobiRepository.IsPhoneNumberAvailable(dobi.Phone))
                {
                    return(new GenericResponse <string>(false, null, "Phone number is not available"));
                }
                else if (!string.IsNullOrWhiteSpace(dobi.PassportNumber))
                {
                    if (!await _dobiRepository.IsPassportNumberAvailable(dobi.PassportNumber))
                    {
                        return(new GenericResponse <string>(false, null, "Passport number is not available"));
                    }
                }
                else if (!string.IsNullOrWhiteSpace(dobi.IcNumber))
                {
                    if (!await _dobiRepository.IsIcNumberAvailable(dobi.IcNumber))
                    {
                        return(new GenericResponse <string>(false, null, "IC number is not available"));
                    }
                }
                else if (!string.IsNullOrWhiteSpace(dobi.DrivingLicense) && !await _dobiRepository.IsDrivingLicenseAvailable(dobi.DrivingLicense))
                {
                    return(new GenericResponse <string>(false, null, "Driving license is not available"));
                }

                dobi.JoinDate = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalMilliseconds;
                var response = await _dobiRepository.AddDobi(dobi);

                if (!response)
                {
                    return(new GenericResponse <string>(false, null, "Error adding Dobi."));
                }
                return(new GenericResponse <string>(true, null, "Dobi added successfully."));
            }
            catch (Exception exception)
            {
                throw new Exception("Error adding dobi" + exception);
            }
        }
示例#3
0
        public async Task <IHttpActionResult> UpdateDobi()
        {
            if (!Request.Content.IsMimeMultipartContent("form-data"))
            {
                this.Request.CreateResponse(HttpStatusCode.UnsupportedMediaType);
            }
            var addedBy = GetManagerInformationFromToken();

            if (addedBy == null)
            {
                return(BadRequest("Invalid admin token."));
            }
            var    dobi     = new Dobi();
            string s3Prefix = ConfigurationManager.AppSettings["S3Prefix"];
            var    provider = await Request.Content.ReadAsMultipartAsync(new InMemoryMultipartStreamProvider());

            foreach (var key in provider.FormData.AllKeys)
            {
                foreach (var val in provider.FormData.GetValues(key))
                {
                    if (key == "DobiId")
                    {
                        dobi.DobiId = val.ToString().Trim();
                        if (string.IsNullOrWhiteSpace(dobi.DobiId))
                        {
                            return(BadRequest("Dobi Id Is Required."));
                        }
                    }
                    else if (key == "Name")
                    {
                        dobi.Name = val.ToString().Trim();
                        if (string.IsNullOrWhiteSpace(dobi.Name))
                        {
                            return(BadRequest("Name Is Required."));
                        }
                    }
                    else if (key == "Phone")
                    {
                        dobi.Phone = val.ToString().Trim();
                        if (string.IsNullOrWhiteSpace(dobi.Phone))
                        {
                            return(BadRequest("Phone Number Is Required"));
                        }
                    }
                    else if (key == "Email")
                    {
                        dobi.Email = val.ToString().Trim();
                        if (string.IsNullOrWhiteSpace(dobi.Email))
                        {
                            return(BadRequest("Email Is Required"));
                        }
                    }
                    else if (key == "Address")
                    {
                        dobi.Address = val.ToString().Trim();
                    }
                    else if (key == "EmergencyContactNumber")
                    {
                        dobi.EmergencyContactNumber = val.ToString().Trim();
                        if (string.IsNullOrWhiteSpace(dobi.EmergencyContactNumber))
                        {
                            return(BadRequest("Emergency Contact Number Is Required"));
                        }
                    }
                    else if (key == "PassportNumber")
                    {
                        dobi.PassportNumber = val.ToString().Trim();
                    }
                    else if (key == "IcNumber")
                    {
                        dobi.IcNumber = val.ToString().Trim();
                    }
                    else if (key == "DrivingLicense")
                    {
                        dobi.DrivingLicense = val.ToString().Trim();
                    }
                    else if (key == "Age")
                    {
                        dobi.Age = int.Parse(val.ToString().Trim());
                        if (dobi.Age < 0)
                        {
                            return(BadRequest("Invalid Age"));
                        }
                    }
                    else if (key == "Sex")
                    {
                        dobi.Sex = val.ToString().Trim();
                    }
                    else if (key == "Salary")
                    {
                        dobi.Salary = double.Parse(val.ToString().Trim());
                    }
                    else if (key == "Photo")
                    {
                        dobi.Photo = val.ToString().Trim();
                    }
                }
            }
            if (provider.Files != null && provider.Files.Count > 0)
            {
                _storageService = new StorageService();
                foreach (var file in provider.Files)
                {
                    var    photoUrl = dobi.DobiId + "/profile/" + "profile_pic.png";
                    Stream stream   = await file.ReadAsStreamAsync();

                    _storageService.UploadFile("dhobi-bucket", photoUrl, stream);
                    dobi.Photo = s3Prefix + photoUrl;
                }
            }
            var response = await _dobiBusiness.UpdateDobi(dobi);

            return(Ok(response));
        }