Ejemplo n.º 1
0
        public IActionResult Create(RegisterAdd model)
        {
            if (ModelState.IsValid)
            {
                var staff = new Staff()
                {
                    Address     = model.Address,
                    DistrictId  = model.DistrictId,
                    Email       = model.Email,
                    Fullname    = model.Fullname,
                    Password    = model.Password,
                    PhoneNumber = model.PhoneNumber,
                    ProvinceId  = model.ProvinceId,
                    WardId      = model.WardId
                };
                var staffId = staffService.CreateStaff(staff);
                if (staffId > 0)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                ModelState.AddModelError("", "System error, please try again later!");
            }
            var registerView = new RegisterView();

            return(View(registerView));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <BaseResponse <StaffViewModel> > > PostAccount([FromBody] CreateStaffRequest request)
        {
            try
            {
                var raw       = Request.Headers.FirstOrDefault(x => x.Key.Equals("Authorization")).Value;
                var requester = IdentityManager.GetUsernameFromToken(raw);
                var roles     = IdentityManager.GetRolesFromToken(raw);

                var result = _staffService.CreateStaff(request, requester, roles);

                if (result == null)
                {
                    return(BadRequest(new ErrorResponse(StatusCodes.Status400BadRequest.ToString()
                                                        , "Failed to create a staff")));
                }

                return(Created(result.Id.ToString(), new BaseResponse <StaffViewModel>()
                {
                    Data = result
                }));
            }
            catch (Exception ex)
            {
                if (ex.Message.StartsWith("ERR"))
                {
                    return(BadRequest(new ErrorResponse(ex.Message)));
                }
                else
                {
                    throw;
                }
            }
        }
Ejemplo n.º 3
0
        public ActionResult Create(Staff model)
        {
            if (string.IsNullOrWhiteSpace(model.FullName) || string.IsNullOrWhiteSpace(model.AccountName))
            {
                Messages.AddErrorMessage("Cần nhập các thông tin bắt buộc!");
                return(View(model));
            }
            IStaffService _staSrv = IoC.Resolve <IStaffService>();

            if (_staSrv.Query.Where(p => p.AccountName.ToUpper() == model.AccountName.Trim().ToUpper()).Count() > 0)
            {
                Messages.AddErrorMessage("Tồn tại tài khoản trên hệ thống.");
                return(View("Create", model));
            }
            Company _currentCom  = ((EInvoiceContext)FXContext.Current).CurrentCompany;
            string  ErrorMessage = "";

            if (_staSrv.CreateStaff(model, _currentCom.id, out ErrorMessage) == true)
            {
                log.Info("Create staff by: " + HttpContext.User.Identity.Name + " Info-- TenNhanVien: " + model.FullName + " TaiKhoanNhanVien: " + model.AccountName + " Email: " + model.Email);
                Messages.AddFlashMessage(Resources.Message.Staff_IMesSuccess);
                return(RedirectToAction("Index"));
            }
            else
            {
                Messages.AddErrorMessage("Lỗi: " + ErrorMessage);
                return(View(model));
            }
        }
 public ActionResult SendMessage(StaffFormModel obj, bool continueEditing)
 {
     obj.Phone = "09090909090";
     if (ModelState.IsValid)
     {
         Staff item = Mapper.Map <StaffFormModel, Staff>(obj);
         _staffService.CreateStaff(item);
     }
     return(RedirectToAction("Index", "Home"));
 }
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            _service.CreateStaff(Staff);

            return(RedirectToPage("Index"));
        }
        public void Post()
        {
            string userId = User.Identity.GetUserId();
            Staff  staff  = new Staff
            {
                Id   = userId,
                Name = User.Identity.Name
            };
            bool userRole = User.IsInRole("Manager");

            staff.StaffCategory = userRole ? (int)StaffsCategory.Manager : (int)StaffsCategory.Employee;
            _staffService.CreateStaff(staff);
        }
        public async Task <IActionResult> CreateStaff([FromBody] StaffDTO staffModel)
        {
            try
            {
                var staff    = StaffMapper.MapDtoToStaffDetails(staffModel, _staffService);
                var staffNew = await _staffService.CreateStaff(staff, staffModel.Languages, staffModel.Teritories);

                return(Ok(staff));
            }
            catch (Exception ex)
            {
                return(BadRequest("Error saving staff!"));
            }
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Post([FromBody] StaffModel model)
        {
            try
            {
                var staff = await _staffService.CreateStaff(model);

                return(StatusCode(201, staff));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(StatusCode(409));
            }
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> CreateStaff([FromBody] UserModel model)
        {
            var user   = _mapper.Map <Users>(model);
            var result = await _userService.CreateUser(user, model.Password);

            if (result != null)
            {
                var staffModel = _mapper.Map <UserModel>(result);
                staffModel.DepartmentId = model.DepartmentId;
                var staff = await _staffService.CreateStaff(staffModel);

                return(Created("", staff));
            }

            return(BadRequest());
        }
Ejemplo n.º 10
0
 public ActionResult Create(StaffFormModel obj, bool continueEditing)
 {
     if (ModelState.IsValid)
     {
         obj.Deleted = false;
         if (obj.Name != null)
         {
             obj.Rename = StringConvert.ConvertShortName(obj.Name);
         }
         Staff item = Mapper.Map <StaffFormModel, Staff>(obj);
         _staffService.CreateStaff(item);
         return(continueEditing ? RedirectToAction("Edit", "Staff", new { id = item.Id })
                          : RedirectToAction("Index", "Staff"));
     }
     else
     {
         return(View("Create", obj));
     }
 }
Ejemplo n.º 11
0
 public void Create(StaffDto staffDto)
 {
     staffService.CreateStaff(staffDto);
 }
Ejemplo n.º 12
0
 public int CreateStaff(StaffVM staffVM)
 {
     return(_staffService.CreateStaff(staffVM.ToStaffDTO()));
 }