Esempio n. 1
0
        //create vessel
        public int createVesselDB(vessel_owner_ref vessel_owner_ref)
        {
            int vessel_id = 0;

            try
            {
                vessel getVesselObject = db.vessels.Where(v => v.registration_id == vessel_owner_ref.vessel.registration_id &&
                                                          v.vessel_no.Equals(vessel_owner_ref.vessel.vessel_no) && v.district_id == vessel_owner_ref.vessel.district_id &&
                                                          v.vessel_status == 1).FirstOrDefault();

                //Vessel is not exist
                if (getVesselObject == null)
                {
                    db.vessel_owner_ref.Add(vessel_owner_ref);  //Save vessel and owner
                    db.SaveChanges();

                    vessel getAboveVesselObject = db.vessels.Where(v => v.registration_id == vessel_owner_ref.vessel.registration_id &&
                                                                   v.vessel_no.Equals(vessel_owner_ref.vessel.vessel_no) && v.district_id == vessel_owner_ref.vessel.district_id &&
                                                                   v.vessel_status == 1).FirstOrDefault();

                    vessel_id = getAboveVesselObject.vessel_id;  //return vessel id after the inserted
                }
                //Vessel is exist
                else
                {
                    vessel_id = getVesselObject.vessel_id;  //return vessel id that already created
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(vessel_id);
        }
Esempio n. 2
0
        public IHttpActionResult SaveTeam([FromBody] TeamDTO entityToUpdate)
        {
            var teamObj = Mapper.Map <Team>(entityToUpdate);

            Log.DebugFormat("LookupController (FetchAllTeams)\n");


            var fetchedEntity = _db.Teams.SingleOrDefault(x => x.id == teamObj.id);

            if (fetchedEntity == null)
            {
                return(BadRequest($"The record cannot be null"));
            }



            try
            {
                _db.Teams.AddOrUpdate(teamObj);
                _db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(BadRequest($"The record was has been modified by someone else"));
            }

            return(Ok(true));
        }
Esempio n. 3
0
        public virtual IHttpActionResult DeleteProfileById(int id)
        {
            Log.DebugFormat("ProfileController (DeleteProfileById)\n");

            try
            {
                var profile = _db.Profiles.SingleOrDefault(x => x.id == id);

                if (profile != null)
                {
                    profile.isDeleted = true;

                    try
                    {
                        _db.SaveChanges();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        var myError = new Error
                        {
                            Code    = "400",
                            Message = "The entity being updated has already been updated by another user...",
                            Data    = null
                        };
                        return(new ErrorResult(myError, Request));
                    }
                }

                Log.DebugFormat("Retrieval of DeleteProfileById was successful.\n");
                return(Ok(true));
            }
            catch (Exception ex)
            {
                Log.DebugFormat(
                    $"Error retrieving DeleteProfileById. The reason is as follows: {ex.Message} {ex.StackTrace}");

                var myError = new Error
                {
                    Code    = "400",
                    Message = "Error retrieving DeleteProfileById",
                    Data    = new object[] { ex.Message, ex.StackTrace }
                };
                return(new ErrorResult(myError, Request));
            }
        }
Esempio n. 4
0
 //insert method
 public int saveUserDB(user user)
 {
     try
     {
         int flag = 0;
         if (db.users.Where(u => u.user_username.Equals(user.user_username) && u.user_status == 1).FirstOrDefault() == null)
         {
             db.users.Add(user);
             db.SaveChanges();
             flag = 1;
         }
         return(flag);
     }
     catch (Exception)
     {
         throw;
     }
 }
        //insert method
        public int saveDistressDB(distress distress)
        {
            int flag = 0;

            try
            {
                if (distress != null)
                {
                    db.distresses.Add(distress);
                    db.SaveChanges();
                    flag = 1;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(flag);
        }
Esempio n. 6
0
 //insert method
 public int saveRegistrationDB(registration registration)
 {
     try
     {
         int flag = 0;
         registration.registration_code = registration.registration_code.ToUpper();  //search fuction in views only accept Capital letters for vessel Registration
         if (db.registrations.Where(r => r.registration_code.Equals(registration.registration_code) && r.registration_status == 1).FirstOrDefault() == null)
         {
             db.registrations.Add(registration);
             db.SaveChanges();
             flag = 1;
         }
         return(flag);
     }
     catch (Exception)
     {
         throw;
     }
 }
 //insert method
 public int saveDistrictDB(district district)
 {
     try
     {
         int flag = 0;
         district.district_code = district.district_code.ToUpper();  //search funtion in views only accept captal for District code
         if (db.districts.Where(d => d.district_status == 1 && d.district_code.Equals(district.district_code)).FirstOrDefault() == null)
         {
             db.districts.Add(district);
             db.SaveChanges();
             flag = 1;
         }
         return(flag);
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 8
0
        //insert method
        public int saveRadioStationDB(radio_station radio_station)
        {
            int flag = 0;

            try
            {
                var result = db.radio_station.Where(r => r.mcs_status == 1 && r.mcs_callsign.Equals(radio_station.mcs_callsign)).FirstOrDefault();
                if (result == null)
                {
                    db.radio_station.Add(radio_station);
                    db.SaveChanges();
                    flag = 1;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(flag);
        }
        //insert method
        public int saveOwnerDB(vessel_owner_ref vessel_owner_ref)
        {
            int flag = 0;

            try
            {
                var result = db.vessel_owner_ref.Where(o => o.owner.owner_nic == vessel_owner_ref.owner.owner_nic && o.owner.owner_status == 1).FirstOrDefault();
                if (result == null)
                {
                    db.vessel_owner_ref.Add(vessel_owner_ref);
                    db.SaveChanges();
                    flag = 1;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(flag);
        }
Esempio n. 10
0
        //insert method
        public int saveVesselDB(vessel_owner_ref vessel_owner_ref)
        {
            int flag = 0;

            try
            {
                var result = db.vessel_owner_ref.Where(v => v.vessel.registration_id == vessel_owner_ref.vessel.registration_id &&
                                                       v.vessel.vessel_no.Equals(vessel_owner_ref.vessel.vessel_no) && v.vessel.district_id == vessel_owner_ref.vessel.district_id && v.vessel.vessel_status == 1).FirstOrDefault();

                if (result == null)
                {
                    db.vessel_owner_ref.Add(vessel_owner_ref);
                    db.SaveChanges();
                    flag = 1;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(flag);
        }
Esempio n. 11
0
        public IHttpActionResult CreateJobType(JobTypeDTO newJobType)
        {
            if (newJobType != null)
            {
                try
                {
                    var localJobTypeToUpdate = Mapper.Map <JobType>(newJobType);
                    _db.JobTypes.Add(localJobTypeToUpdate);
                    _db.SaveChanges();
                }
                catch (Exception ex)
                {
                    Log.DebugFormat(
                        $"Error creating new JobType. The reason is as follows: {ex.Message} {ex.StackTrace}\n");
                    var myError = new Error
                    {
                        Code    = "400",
                        Message = "Error creating new JobType",
                        Data    = new object[] { ex.Message, ex.StackTrace }
                    };
                    return(new ErrorResult(myError, Request));
                }

                Log.DebugFormat("The new JobType record has been created successfully.\n");
            }

            Log.DebugFormat($"Error creating new JobType. JobType cannot be null\n");
            var myError2 = new Error
            {
                Code    = "400",
                Message = "Error creating new JobType. JobType cannot be null",
                Data    = null
            };

            return(new ErrorResult(myError2, Request));
        }
Esempio n. 12
0
        //insert method
        public int saveLicencesDB(licence licence)
        {
            int flag = 0;

            try
            {
                var result = db.licences.Where(l => l.licence_callsign.Equals(licence.licence_callsign) || l.licence_trc_fileno.Equals(licence.licence_trc_fileno) && l.licence_status == 1).FirstOrDefault();

                if (result == null)
                {
                    db.licences.Add(licence);
                    db.SaveChanges();
                    flag = 1;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(flag);
        }
Esempio n. 13
0
        public IHttpActionResult Post(string filename, int profileId, int docmentTypeId)
        {
            var fileObj     = new ProfileDocument();
            var thisProfile = db.Profiles.SingleOrDefault(x => x.id == profileId);

            if (thisProfile == null)
            {
                Log.DebugFormat(
                    "Error retrieving Profile. The profile cannot be found");

                var myError = new Error
                {
                    Code    = "400",
                    Message = "Error retrieving Profile. The profile cannot be found",
                    Data    = null
                };

                return(new ErrorResult(myError, Request));
            }

            // Check for valid file types
            var extension = Path.GetExtension(filename.Trim());

            if (!string.IsNullOrEmpty(extension))
            {
                extension = extension.TrimStart('.'); //remove full stop
                var tagList = new List <string> {
                    "pdf", "doc", "docx", "txt"
                };
                var exists = tagList.Any(val => val.Contains(extension.ToLower()));

                if (exists)
                {
                    fileObj.mimeType         = extension.ToLower();
                    fileObj.originalFileName = filename.ToLower().Trim();
                }
            }
            else
            {
                Log.DebugFormat("Missing or disallowed file extension");
                var myError = new Error
                {
                    Code    = "400",
                    Message = "Missing or disallowed file extension",
                    Data    = null
                };
                return(new ErrorResult(myError, Request));
            }

            // Read data here
            var task = Request.Content.ReadAsStreamAsync();

            task.Wait();
            var requestStream = task.Result;

            try
            {
                var byteArray = ReadFully(requestStream);
                var compress  = Compress(byteArray);

                fileObj.documentData   = compress;
                fileObj.dateObtained   = DateTime.Now;
                fileObj.profileId      = profileId;
                fileObj.documentTypeId = docmentTypeId;

                db.ProfileDocuments.Add(fileObj);
                db.SaveChanges();
            }
            catch (IOException ex)
            {
                Log.DebugFormat(
                    $"Error storing ProfileDocument. The reason is as follows: {ex.Message} {ex.StackTrace}");
                var myError = new Error
                {
                    Code    = "400",
                    Message = "Error storing ProfileDocument",
                    Data    = new object[] { ex.Message, ex.StackTrace }
                };
                return(new ErrorResult(myError, Request));
            }

            return(Ok());
        }