示例#1
0
        public async Task <IActionResult> UpdateOpenTime(int id, [FromBody] OpenTimeModel openTimeModel)
        {
            if (ModelState.IsValid)
            {
                if (openTimeModel == null)
                {
                    return(BadRequest($"{nameof(openTimeModel)} can not be null."));
                }

                var openTime = _unitOfWork.OpenTimes.Find(id);
                if (openTime == null)
                {
                    return(NotFound());
                }

                _mapper.Map(openTimeModel, openTime);
                _unitOfWork.OpenTimes.Update(openTime);
                int result = await _unitOfWork.SaveChangesAsync();

                if (result < 1)
                {
                    return(NoContent());
                }

                return(Ok(openTime));
            }

            return(BadRequest(ModelState));
        }
示例#2
0
        public void Add(LogData logData)
        {
            OpenTimeModel model = new OpenTimeModel();

            model.Init(logData);
            OpenTimeCollection.Add(model);
        }
示例#3
0
        private void InitDemo()
        {
            OpenTimeModel model = new OpenTimeModel();

            model.CMP            = "com.android.deskclock/.DeskClock";
            model.Alias          = "DeskClock";
            model.StartStamp     = "2014-05-18 23:18:50.350";
            model.DisplayedStamp = "2014-05-18 23:18:52.690";
            model.Duration       = 2069d;
            model.ActualTimeSpan = 2340d;
            OpenTimeCollection.Add(model);

            model                = new OpenTimeModel();
            model.CMP            = "com.android.calendar/.AllInOneActivity";
            model.Alias          = "Calendar";
            model.StartStamp     = "2014-05-18 23:18:50.700";
            model.DisplayedStamp = "2014-05-18 23:18:52.690";
            model.Duration       = 1605d;
            model.ActualTimeSpan = 1990d;
            OpenTimeCollection.Add(model);

            model                = new OpenTimeModel();
            model.CMP            = "com.android.calculator2/.Calculator";
            model.Alias          = "calculator2";
            model.StartStamp     = "2014-05-18 23:18:57.270";
            model.DisplayedStamp = "2014-05-18 23:18:58.320";
            model.Duration       = 813d;
            model.ActualTimeSpan = 1050d;
            OpenTimeCollection.Add(model);

            model                = new OpenTimeModel();
            model.CMP            = "com.android.settings/.Settings";
            model.Alias          = "Settings";
            model.StartStamp     = "2014-05-18 23:19:01.830";
            model.DisplayedStamp = "2014-05-18 23:19:02.940";
            model.Duration       = 965d;
            model.ActualTimeSpan = 1110d;
            OpenTimeCollection.Add(model);
        }
示例#4
0
        public async Task <IActionResult> AddOpenTime([FromBody] OpenTimeModel openTimeModel)
        {
            if (ModelState.IsValid)
            {
                if (openTimeModel == null)
                {
                    return(BadRequest($"{nameof(openTimeModel)} can not be null."));
                }

                var openTime = _mapper.Map <OpenTime>(openTimeModel);
                _unitOfWork.OpenTimes.Add(openTime);
                int result = await _unitOfWork.SaveChangesAsync();

                if (result < 1)
                {
                    return(NoContent());
                }

                return(Ok(openTime));
            }

            return(BadRequest(ModelState));
        }