Beispiel #1
0
        /// <summary>Tạo mới nhân viên</summary>
        /// <param name="request">The request.</param>
        /// <returns>
        ///   <br />
        /// </returns>
        /// <Modified>
        /// Name     Date         Comments
        /// thainh2  5/10/2021   created
        /// </Modified>
        public async Task <ApiResult <string> > Create(StaffCreateRequest request)
        {
            try
            {
                // Check trùng email
                var staffObj = await _context.Staffs.FirstOrDefaultAsync(t => t.Email == request.Email.Trim() && t.Status == true);

                if (staffObj != null)
                {
                    return(new ApiErrorResult <string>("Email đã tồn tại"));
                }

                //Check trùng số điện thoại
                var objStaff_PhoneNumber = await _context.Staffs.FirstOrDefaultAsync(t => t.Tel == request.Tel.Trim() && t.Status == true);

                if (objStaff_PhoneNumber != null)
                {
                    return(new ApiErrorResult <string>("Số điện thoại đã tồn tại"));
                }

                var staff = new Staff()
                {
                    Name         = SystemConstants.StripHTML(request.Name),
                    NameUnsigned = SystemConstants.ConvertToUnSign(SystemConstants.StripHTML(request.Name)),
                    Email        = request.Email,
                    Tel          = request.Tel,
                    Status       = true,
                    CreateBy     = request.CreateBy,
                    CreateDate   = DateTime.Now
                };
                _context.Staffs.Add(staff);
                await _context.SaveChangesAsync();

                return(new ApiSuccessResult <string>(staff.Id.ToString()));
            }
            catch (Exception e)
            {
                var logRequest = new LogWritelogRequest()
                {
                    MethodName  = "StaffService_Create",
                    CreateDate  = DateTime.Now,
                    Description = e.Message
                };
                await WriteLog(logRequest);

                throw new ThainhLabExeption(e.Message);
            }
        }
Beispiel #2
0
 /// <summary>Ghi log vào database</summary>
 /// <param name="request">The request.</param>
 /// <returns>
 ///   <br />
 /// </returns>
 /// <Modified>
 /// Name     Date         Comments
 /// thainh2  5/10/2021   created
 /// </Modified>
 public async Task <int> WriteLog(LogWritelogRequest request)
 {
     try
     {
         var log = new Log()
         {
             MethodName  = request.MethodName,
             Description = request.Description,
             CreateDate  = request.CreateDate
         };
         _context.Logs.Add(log);
         return(await _context.SaveChangesAsync());
     }
     catch (Exception e)
     {
         throw new ThainhLabExeption(e.Message);
     }
 }