Ejemplo n.º 1
0
        public OvertimeProfile()
        {
            CreateMap <OvertimeForm, OvertimeFormMain>()
            .ForMember(dst => dst.Y, map => map.MapFrom(src => src.YMD.Year))
            .ForMember(dst => dst.M, map => map.MapFrom(src => src.YMD.Month))
            .ForMember(dst => dst.D, map => map.MapFrom(src => src.YMD.Day))
            .ForMember(dst => dst.CreatedDate, map => map.MapFrom(src => DateTime.Now));

            CreateMap <OvertimeFormMain, OvertimeForm>()
            .ForMember(dst => dst.YMD, map => map.MapFrom(src => new DateTime(src.Y, src.M, src.D)));

            CreateMap <OvertimeUser, OvertimeFormDetails>()
            .ForMember(dst => dst.Id, map => map.MapFrom(src => src.Id))
            .ForMember(dst => dst.Name, map => map.MapFrom(src => src.Name));

            CreateMap <OvertimeFormInput, OvertimeFormES>()
            .ConvertUsing((src, dst) =>
            {
                dst       = new OvertimeFormES();
                dst.Form  = Mapper.Map <OvertimeForm, OvertimeFormMain>(src.Form);
                dst.Users = new List <OvertimeFormDetails>();
                src.Users = src.Users ?? new List <OvertimeUser>();
                foreach (var user in src.Users)
                {
                    var detail = Mapper.Map <OvertimeUser, OvertimeFormDetails>(user);
                    detail.Y   = src.Form.YMD.Year;
                    detail.M   = src.Form.YMD.Month;
                    detail.D   = src.Form.YMD.Day;
                    dst.Users.Add(detail);
                }
                return(dst);
            });
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Dst = Mapper.Map <OvertimeFormInput, OvertimeFormES>(Input);

            var Rcid    = _context.GetNewRcId();
            var rtId    = _context.GetRtId("OvertimeForm");
            var repCase = new EsRepCase
            {
                RcId          = Rcid,
                RtId          = rtId,
                LstFiller     = 2,
                LstFillerName = User.Identity.Name,
                LstFillDate   = DateTime.Now,
            };

            Dst.Form.ExcelServerRcid = Rcid;
            Dst.Form.ExcelServerRtid = rtId;
            foreach (var user in Dst.Users)
            {
                user.ExcelServerRcid = Rcid;
                user.ExcelServerRtid = rtId;
            }

            _context.EsRepCase.Add(repCase);
            _context.OvertimeFormMain.Add(Dst.Form);
            _context.OvertimeFormDetails.AddRange(Dst.Users);

            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }