public IActionResult ScheduleAppointmentAddOrEdit([FromBody] ScheduleAppointmentModel model)
        {
            APIJsonResult result = new APIJsonResult();

            result.Access  = true;
            result.success = true;
            var currentUserToken = User.Claims.SingleOrDefault(x => x.Type == "UserRole") != null?User.Claims.SingleOrDefault(x => x.Type == "UserRole").Value : null;

            if (currentUserToken == null)
            {
                result.Msg.Add("Session Time Out");
                result.success = false;
                result.Access  = true;
                return(Ok(result));
            }
            if (model == null)
            {
                result.Msg.Add("Model Null");
                result.success = false;
                result.Access  = true;
                return(Ok(result));
            }

            if (model.Id == 0)
            {
                ScheduleAppointment scheduleAppointment = new ScheduleAppointment()
                {
                    Notes       = model.Notes,
                    UserId      = Convert.ToInt32(User.Claims.SingleOrDefault(x => x.Type == "UserId") != null ? User.Claims.SingleOrDefault(x => x.Type == "UserId").Value : null),
                    VisitType   = model.VisitType,
                    Appointment = PublicFunctions.ConvertTimestampToDateTime(model.Appointment),
                    DoctorId    = model.DoctorId,
                    Status      = 1,
                };
                _scheduleAppointment.Add(scheduleAppointment);
                _context.SaveChanges();
            }
            else
            {
                var scheduleAppointment = _scheduleAppointment.Where(x => x.Id == model.Id).FirstOrDefault();
                if (scheduleAppointment == null)
                {
                    result.Msg.Add("Not found");
                    result.success = false;
                    result.Access  = true;
                    return(Ok(result));
                }
                scheduleAppointment.Notes       = model.Notes;
                scheduleAppointment.VisitType   = model.VisitType;
                scheduleAppointment.Appointment = PublicFunctions.ConvertTimestampToDateTime(model.Appointment);
                scheduleAppointment.DoctorId    = model.DoctorId;
                _scheduleAppointment.Update(scheduleAppointment);
                _context.SaveChanges();
            }
            return(Ok(result));
        }
Exemplo n.º 2
0
        public ActionResult RegisterUser(UserRegisterApi userRegister)
        {
            _localizer.HeaderLanguage = AcceptLanguage;
            APIJsonResult result   = new APIJsonResult();
            UserProfile   userDate = new UserProfile();

            result.Access = true;

            if (string.IsNullOrEmpty(userRegister.Email) || string.IsNullOrEmpty(userRegister.Name) ||
                string.IsNullOrEmpty(userRegister.Mobile))
            {
                result.success = false;
                result.Msg.Add("Admin.All fields must be filled");
                result.data = new APILoginView();
                return(Ok(result));
            }
            //#region Validate Phone Number
            //Regex pattern = new Regex(RegexStrings.MobileRegex);
            //if (!pattern.IsMatch(userRegister.Mobile))
            //{
            //    result.success = false;
            //    result.Msg.Add(_localizer.GetString("Admin.Invalid Mobile number"));
            //    result.data = null;
            //    return Ok(result);
            //}
            //#endregion
            #region Validate Email
            Regex emailPattern = new Regex(RegexStrings.EmailRegex);
            if (!emailPattern.IsMatch(userRegister.Email))
            {
                result.success = false;
                result.Msg.Add(_localizer.GetString("Admin.Invalid Email Address "));
                result.data = null;
                return(Ok(result));
            }
            #endregion
            result.success = false;
            var user      = new User();
            var Existuser = _context.Users.Where(x => x.Email == userRegister.Email && x.IsDeleted != true).Include(f => f.fk_UserRoleMap).ThenInclude(g => g.UserRole).ThenInclude(p => p.fk_UserRolePermMap).ThenInclude(h => h.Permission).FirstOrDefault();
            if (Existuser == null)
            {
                using (var algorithm = MD5.Create()) //or MD5 SHA256 etc.
                {
                    var hashedBytes = algorithm.ComputeHash(Encoding.UTF8.GetBytes(userRegister.Password));

                    userRegister.Password = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                }
                using (var algorithm = MD5.Create()) //or MD5 SHA256 etc.
                {
                    var hashedBytes = algorithm.ComputeHash(Encoding.UTF8.GetBytes(userRegister.ConfirmPassword));

                    userRegister.ConfirmPassword = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
                }

                if (userRegister.Password.Equals(userRegister.ConfirmPassword))
                {
                    user = new User()
                    {
                        Email       = userRegister.Email,
                        Mobile      = userRegister.Mobile,
                        Name        = userRegister.Name,
                        Password    = userRegister.Password,
                        Activation  = true,
                        Address     = userRegister.Address,
                        BirthDate   = PublicFunctions.ConvertTimestampToDateTime(userRegister.BirthDate),
                        BloodType   = userRegister.BloodType,
                        InsuranceNo = userRegister.InsuranceNo,
                        //InsuranceImage = userRegister.InsuranceImage

                        //JwtToken = result.token = Token.GenerateToken(user.Id.ToString()),
                    };
                    //user.Activation = false;
                    _context.Users.Add(user);
                    _context.SaveChanges();
                    user.fk_UserRoleMap.Add(new UserRoleMap()
                    {
                        UserId     = user.Id,
                        User       = user,
                        UserRoleId = 9,
                        UserRole   = _context.UserRoles.Where(x => x.Id == 9).FirstOrDefault()
                    });
                    if (userRegister.InsuranceImage != null || userRegister.InsuranceImage.Length > 0)
                    {
                        var file = userRegister.InsuranceImage;

                        //string uploadedCoverImage64 = PublicFunctions.ConvertTo64Bit(userRegister.InsuranceImage);
                        user.InsuranceImage = userRegister.InsuranceImage.FileName;

                        //user.InsuranceImage = @"\Upload\InsuranceImage\" + user.Id + @"\" + user.InsuranceImage;

                        var CoverImagetPath = _paths._insuranceImage + @"\Upload\InsuranceImage\" + user.Id + "/";
                        if (!Directory.Exists(CoverImagetPath))
                        {
                            Directory.CreateDirectory(CoverImagetPath);
                        }
                        using (var fileStream = new FileStream(CoverImagetPath + userRegister.InsuranceImage.FileName, FileMode.Create))
                        {
                            userRegister.InsuranceImage.CopyTo(fileStream);
                        }
                        //file.CopyToAsync(new FileStream(CoverImagetPath + user.InsuranceImage, FileMode.Create));
                    }
                    if (userRegister.PersonalImage != null || userRegister.PersonalImage.Length > 0)
                    {
                        var file = userRegister.InsuranceImage;

                        //string uploadedCoverImage64 = PublicFunctions.ConvertTo64Bit(userRegister.PersonalImage);
                        user.PersonalImage = userRegister.PersonalImage.FileName;

                        //user.PersonalImage = @"\Upload\PersonalImage\" + user.Id + @"\" + user.PersonalImage;

                        var CoverImagetPath = _paths._insuranceImage + @"\Upload\PersonalImage\" + user.Id + "/";
                        if (!Directory.Exists(CoverImagetPath))
                        {
                            Directory.CreateDirectory(CoverImagetPath);
                        }
                        using (var fileStream = new FileStream(CoverImagetPath + userRegister.PersonalImage.FileName, FileMode.Create))
                        {
                            userRegister.PersonalImage.CopyTo(fileStream);
                        }
                        //file.CopyToAsync(new FileStream(CoverImagetPath + user.InsuranceImage, FileMode.Create));
                    }
                    _context.Users.Update(user);
                    _context.SaveChanges();
                    userDate.Id     = user.Id;
                    userDate.Email  = user.Email;
                    userDate.Mobile = user.Mobile;
                    userDate.Name   = user.Name;
                    // result.Msg.Add("Admin.Wait for activation from Admin");
                    result.Msg.Add("Admin.Successfully Registeration ");
                }
                else
                {
                    result.success = false;
                    result.Msg.Add("Admin.User Password Not Match");
                    result.data = new APILoginView();
                    return(Ok(result));
                }
            }
            else
            {
                result.success = false;
                result.Msg.Add("Admin.duplicate email address");
                result.data = new APILoginView();
                return(Ok(result));
            }
            result.success = true;
            result.data    = userDate;
            return(Ok(result));
        }
Exemplo n.º 3
0
        public ActionResult UpdateSurgicalHistory(SurgicalHistoryViewModel model)
        {
            var userId = User.Claims.SingleOrDefault(x => x.Type == "UserId") != null?User.Claims.SingleOrDefault(x => x.Type == "UserId").Value : null;

            int UserId = 0;

            Int32.TryParse(userId, out UserId);
            //new ExceptionLog().WriteException(JsonConvert.SerializeObject(model).ToString());
            APIJsonResult result = new APIJsonResult();

            result.Access = true;
            if (UserId == 0 || model == null)
            {
                result.success = false;
                result.Msg.Add("NoUser");
                return(Ok(result));
            }
            try
            {
                if (model.Id < 1)
                {
                    //add mode
                    PastSurgicalHistory entity = new PastSurgicalHistory();
                    entity.Name         = model.Name;
                    entity.SurgicalDate = PublicFunctions.ConvertTimestampToDateTime(model.SurgicalDate);
                    entity.UserId       = UserId;
                    entity.CreatedBy    = UserId;
                    entity.CreatedDate  = DateTime.Now;
                    _PastSurgicalHistory.Add(entity);
                    _context.SaveChanges();
                    if (model.Images != null && model.Images.Count() > 0)
                    {
                        model.Images.ToList().ForEach(a =>
                        {
                            var CoverImagetPath = _paths.SurgicalHistoryImages + UserId + @"\";
                            if (!Directory.Exists(CoverImagetPath))
                            {
                                Directory.CreateDirectory(CoverImagetPath);
                            }
                            using (var fileStream = new FileStream(CoverImagetPath + a.FileName, FileMode.Create))
                            {
                                a.CopyTo(fileStream);
                            }
                            PastSurgicalHistoryImage images = new PastSurgicalHistoryImage();
                            images.Image      = a.FileName;
                            images.SurgicalId = entity.Id;
                            _PastSurgicalHistoryImage.Add(images);
                            _context.SaveChanges();
                        });
                    }
                }
                else
                {
                    PastSurgicalHistory entity = _PastSurgicalHistory.Where(a => a.Id == model.Id).FirstOrDefault();
                    entity.Name         = model.Name;
                    entity.SurgicalDate = PublicFunctions.ConvertTimestampToDateTime(model.SurgicalDate);
                    entity.UpdateBy     = UserId;
                    entity.UserId       = UserId;
                    entity.UpdateDate   = DateTime.Now;
                    _PastSurgicalHistory.Update(entity);
                    _context.SaveChanges();

                    //Delete the Images
                    var oldImages = _PastSurgicalHistoryImage.Where(a => a.SurgicalId == model.Id).ToList();
                    if (oldImages != null && oldImages.Count() > 0)
                    {
                        oldImages.ForEach(a =>
                        {
                            _PastSurgicalHistoryImage.Remove(a);
                            _context.SaveChanges();
                        });
                    }
                    //Add new Images
                    if (model.Images != null && model.Images.Count() > 0)
                    {
                        model.Images.ToList().ForEach(a =>
                        {
                            var CoverImagetPath = _paths.SurgicalHistoryImages + UserId + "/";
                            if (!Directory.Exists(CoverImagetPath))
                            {
                                Directory.CreateDirectory(CoverImagetPath);
                            }
                            using (var fileStream = new FileStream(CoverImagetPath + a.FileName, FileMode.Create))
                            {
                                a.CopyToAsync(fileStream);
                            }
                            PastSurgicalHistoryImage images = new PastSurgicalHistoryImage();
                            images.Image      = a.FileName;
                            images.SurgicalId = entity.Id;
                            _PastSurgicalHistoryImage.Add(images);
                            _context.SaveChanges();
                        });
                    }
                }
            }
            catch (Exception e)
            {
                result.data = e.Message;
            }

            return(Ok(result));
        }