Beispiel #1
0
        public async Task <ActionResult> PostLuggageAsync(SaveLuggageDTO saveLuggageDTO)
        {
            // Mapping: SaveLuggage
            var res = await _service.AddLuggageAsync(saveLuggageDTO);

            return(res);
        }
        public async Task <ActionResult> UpdateLuggageAsync(int id, SaveLuggageDTO saveLuggageDTO)
        {
            var luggage = await _unitOfWork.Luggages.GetByAsync(id);

            // Check luggage exists
            if (luggage == null)
            {
                return(NotFound(new { Id = "Mã hành lý này không tồn tại." }));
            }

            // Check weight of luggage exists except self
            var luggageExist = await _unitOfWork.Luggages.FindAsync(l =>
                                                                    l.LuggageWeight == saveLuggageDTO.LuggageWeight &&
                                                                    l.Id != id);

            if (luggageExist.Count() != 0)
            {
                return(BadRequest(new { LuggageWeight = "Khối lượng hành lý đã được thiết lập" }));
            }

            // Mapping: SaveLuggage
            _mapper.Map <SaveLuggageDTO, Luggage>(saveLuggageDTO, luggage);

            await _unitOfWork.CompleteAsync();

            return(Ok(new { success = true, data = luggage, message = "Sửa thành công." }));
        }
        public async Task <ActionResult> AddLuggageAsync(SaveLuggageDTO saveLuggageDTO)
        {
            // Mapping: SaveLuggage
            var luggage = _mapper.Map <SaveLuggageDTO, Luggage>(saveLuggageDTO);

            // Check weight of luggage exists
            var luggageExist = await _unitOfWork.Luggages.FindAsync(l =>
                                                                    l.LuggageWeight.Equals(luggage.LuggageWeight));

            if (luggageExist.Count() != 0)
            {
                return(BadRequest(new { LuggageWeight = "Khối lượng hành lý đã được thiết lập" }));
            }

            await _unitOfWork.Luggages.AddAsync(luggage);

            await _unitOfWork.CompleteAsync();

            return(Ok(new { success = true, message = "Thêm thành công" }));
        }
Beispiel #4
0
        public async Task <ActionResult> PutLuggageAsync(int id, SaveLuggageDTO saveLuggageDTO)
        {
            var luggage = await _service.UpdateLuggageAsync(id, saveLuggageDTO);

            return(luggage);
        }