Пример #1
0
        public async Task <ActionResult> UpdateVehicleMaintenanceInfo([FromBody] VehicleMaintenanceInfo data, string username, string vehicleId)
        {
            try
            {
                if (data != null && username != null && vehicleId != null)
                {
                    var delete = await MH.DeleteSingleObject(vehiclemaintenanceinfo_collection, "VehicleId", vehicleId, null, null);

                    if (delete != null)
                    {
                        var insert = MH.InsertNewVehicleMaintenanceInfo(data, vehiclemaintenanceinfoCollection);

                        if (insert != null)
                        {
                            var getVehicle = MH.GetSingleObject(vehiclemaintenanceinfo_collection, "VehicleId", vehicleId, null, null).Result;
                            AL.CreateLog(username, "UpdateVehicleMaintenanceInfo", BsonSerializer.Deserialize <VehicleMaintenanceInfo>(getVehicle), data, activitylog_collection);
                            return(Ok(new ResponseData
                            {
                                Code = "200",
                                Message = "Updated"
                            }));
                        }
                        else
                        {
                            return(BadRequest(new ResponseData
                            {
                                Code = "401",
                                Message = "Update failed"
                            }));
                        }
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "404",
                            Message = "Vehicle maintenance info not found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "402",
                        Message = "Bad request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("VehicleController", "UpdateVehicleMaintenanceInfo", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }
Пример #2
0
        public ActionResult InsertVehicleMaintenanceInfo([FromBody] VehicleMaintenanceInfo data, string username)
        {
            try
            {
                if (data != null && username != null)
                {
                    var check = MH.CheckForData(vehiclemaintenanceinfo_collection, "VehicleNo", data.VehicleNo, null, null).Result;
                    if (check == false)
                    {
                        #region Calculate Vehicle id
                        var getVehicles = MH.GetListOfObjects(vehiclemaintenanceinfo_collection, null, null, null, null).Result;
                        if (getVehicles.Count == 0)
                        {
                            data.VehicleId = "VC-1";
                        }
                        else
                        {
                            List <long> idList = new List <long>();
                            foreach (var vehicle in getVehicles)
                            {
                                VehicleMaintenanceInfo vehicleInfo = BsonSerializer.Deserialize <VehicleMaintenanceInfo>(vehicle);
                                long seperatedId = Convert.ToInt64(vehicleInfo.VehicleId.Substring(vehicleInfo.VehicleId.LastIndexOf('-') + 1));
                                idList.Add(seperatedId);
                            }
                            var maxId = idList.Max();
                            data.VehicleId = "VC-" + (maxId + 1);
                        }
                        #endregion
                        data.IsActive = true;



                        var insert = MH.InsertNewVehicleMaintenanceInfo(data, vehiclemaintenanceinfoCollection);
                        if (insert == true)
                        {
                            return(Ok(new ResponseData
                            {
                                Code = "200",
                                Message = "Inserted",
                                Data = data
                            }));
                        }
                        else
                        {
                            return(BadRequest(new ResponseData
                            {
                                Code = "401",
                                Message = "Vehicle maintenance info with same id is already added"
                            }));
                        }
                    }
                    else
                    {
                        return(BadRequest(new ResponseData
                        {
                            Code = "402",
                            Message = "Vehicle with same reg number is found"
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new ResponseData
                    {
                        Code = "403",
                        Message = "Bad Request"
                    }));
                }
            }
            catch (Exception ex)
            {
                SL.CreateLog("VehicleController", "InsertVehicleMaintenanceInfo", ex.Message);
                return(BadRequest(new ResponseData
                {
                    Code = "400",
                    Message = "Failed",
                    Data = ex.Message
                }));
            }
        }