Ejemplo n.º 1
0
        public DemoModelDto CreateOrEditDemoModel(DemoModelInput demoModelInput)
        {
            DemoModel demoModelEntity = null;

            if (demoModelInput.Id == 0)
            {
                // Insert
                demoModelEntity = ObjectMapper.Map <DemoModel>(demoModelInput);
                SetAuditInsert(demoModelEntity);
                demoModelRepository.Insert(demoModelEntity);
                CurrentUnitOfWork.SaveChanges();
            }
            else
            {
                // Update
                demoModelEntity = demoModelRepository.GetAll().Where(x => x.IsDelete == false).SingleOrDefault(x => x.Id == demoModelInput.Id);
                if (demoModelEntity == null)
                {
                    return(null);
                }
                ObjectMapper.Map(demoModelInput, demoModelEntity);
                SetAuditEdit(demoModelEntity);
                demoModelRepository.Update(demoModelEntity);
                CurrentUnitOfWork.SaveChanges();
            }

            return(ObjectMapper.Map <DemoModelDto>(demoModelEntity));
        }
Ejemplo n.º 2
0
        ///
        public DemoModelDto CreateDemo(DemoModelInput demoModelInput)
        {
            DemoModelDto demoModelEntity = null;

            using (IDbConnection con = new SqlConnection(connectionString))
            {
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                demoModelEntity = con.QueryFirst <DemoModelDto>("CreateDemo @Info,@Value,@Date", new
                {
                    Value = demoModelInput.Value,
                    Info  = demoModelInput.Info,
                    Date  = demoModelInput.Date
                });
            }
            return(demoModelEntity);
        }
Ejemplo n.º 3
0
 public DemoModelDto CreateOrEditDemoModel([FromBody] DemoModelInput input)
 {
     return(demoModelAppService.CreateOrEditDemoModel(input));
 }