Example #1
0
        public EmployeeLocation InsertEmployeeLocation(EmployeeLocation objEmployeeLocation)
        {
            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                var result = new EmployeeLocation();

                IDbTransaction trn = connection.BeginTransaction();

                string sql = @"INSERT INTO EmployeeLocation(LocationRefNo,LocationName,CreatedBy,CreatedDate,OrganizationId,isActive) 
                               VALUES(@LocationRefNo,@LocationName,@CreatedBy,@CreatedDate,@OrganizationId,1);
                               SELECT CAST(SCOPE_IDENTITY() as int)";
                try
                {
                    int internalid = DatabaseCommonRepository.GetInternalIDFromDatabase(connection, trn, typeof(EmployeeLocation).Name, "0", 1);
                    objEmployeeLocation.LocationRefNo = "L/" + internalid;

                    int id = connection.Query <int>(sql, objEmployeeLocation, trn).Single();
                    objEmployeeLocation.LocationId = id;
                    //connection.Dispose();
                    InsertLoginHistory(dataConnection, objEmployeeLocation.CreatedBy, "Create", "EmployeeLocation", id.ToString(), "0");
                    trn.Commit();
                }
                catch (Exception ex)
                {
                    trn.Rollback();
                    objEmployeeLocation.LocationId    = 0;
                    objEmployeeLocation.LocationRefNo = null;
                }
                return(objEmployeeLocation);
            }
        }
Example #2
0
        public ActionResult Delete(EmployeeLocation model)
        {
            int result = new EmployeeLocationRepository().DeleteEmployeeLocation(model);

            if (result == 0)
            {
                TempData["Success"]      = "Deleted Successfully!";
                TempData["CountryRefNo"] = model.LocationRefNo;
                return(RedirectToAction("Create"));
            }
            else
            {
                if (result == 1)
                {
                    TempData["error"]         = "Sorry!! You Cannot Delete This Designation It Is Already In Use";
                    TempData["LocationRefNo"] = null;
                }
                else
                {
                    TempData["error"]         = "Oops!!..Something Went Wrong!!";
                    TempData["LocationRefNo"] = null;
                }
                return(RedirectToAction("Create"));
            }
        }
Example #3
0
        public ActionResult Edit(EmployeeLocation model)
        {
            model.OrganizationId = OrganizationId;
            model.CreatedDate    = System.DateTime.Now;
            model.CreatedBy      = UserID.ToString();


            var  repo     = new EmployeeLocationRepository();
            bool isexists = repo.IsFieldExists(repo.ConnectionString(), "EmployeeLocation", "LocationName", model.LocationName, "LocationId", model.LocationId);

            if (!isexists)
            {
                var result = new EmployeeLocationRepository().UpdateEmployeeLocation(model);
                if (result.LocationId > 0)
                {
                    TempData["Success"]      = "Updated Successfully!";
                    TempData["CountryRefNo"] = result.LocationRefNo;
                    return(RedirectToAction("Create"));
                }

                else
                {
                    TempData["error"]        = "Oops!!..Something Went Wrong!!";
                    TempData["CountryRefNo"] = null;
                    return(View("Create", model));
                }
            }
            else
            {
                TempData["error"]        = "This Name Alredy Exists!!";
                TempData["CountryRefNo"] = null;
                return(View("Create", model));
            }
        }
Example #4
0
        protected void GridViewLocation_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                switch (e.CommandName.ToLower())
                {
                case "removeemployeelocation":
                {
                    EmployeeLocation.DeleteEmployeeLocationByEmployeeLocationId(this.employeeId, Convert.ToInt32(e.CommandArgument));

                    if (DropDownListLocation.SelectedItem.Text != "CENTRAL")
                    {
                        EmployeeRegion.DeleteEmployeeRegionByLocationId(this.employeeId, Convert.ToInt32(e.CommandArgument));

                        BindEmployeeRegionList();
                    }

                    BindEmployeeLocationList();

                    break;
                }
                }
            }
            catch (System.Data.SqlClient.SqlException sqlEx)
            {
                LabelError.Text = "";
                for (int i = 0; i < sqlEx.Errors.Count; i++)
                {
                    LabelError.Text += (sqlEx.Errors[i].Message + "<br />");
                }
                PanelError.Visible = true;
            }
        }
Example #5
0
        public ActionResult DeleteConfirmed(int id)
        {
            EmployeeLocation employeeLocation = _employeeLocationService.GetById(id);

            _employeeLocationService.Delete(employeeLocation.ID);
            return(RedirectToAction("Index"));
        }
Example #6
0
        public int DeleteEmployeeLocation(EmployeeLocation objEmployeeLocation)
        {
            int result = 0;

            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                string sql = @" Update EmployeeLocation Set isActive=0 WHERE LocationId=@LocationId";
                try
                {
                    var id = connection.Execute(sql, objEmployeeLocation);
                    objEmployeeLocation.LocationId = id;
                    InsertLoginHistory(dataConnection, objEmployeeLocation.CreatedBy, "Delete", "EmployeeLocation", id.ToString(), "0");
                    result = 0;
                }
                catch (SqlException ex)
                {
                    int err = ex.Errors.Count;
                    if (ex.Errors.Count > 0) // Assume the interesting stuff is in the first error
                    {
                        switch (ex.Errors[0].Number)
                        {
                        case 547:     // Foreign Key violation
                            result = 1;
                            break;

                        default:
                            result = 2;
                            break;
                        }
                    }
                }

                return(result);
            }
        }
Example #7
0
        public ActionResult Create()
        {
            ViewBag.Title = "Create";
            EmployeeLocation Employee = new EmployeeLocation();

            Employee.LocationRefNo = new EmployeeLocationRepository().GetRefNo(Employee);
            return(View(Employee));
        }
Example #8
0
        public async Task NewEmployeeLocation(EmployeeLocation employeeLocation)
        {
            var random = new Random();

            employeeLocation.Latitude  += (float)random.NextDouble();
            employeeLocation.Longitude += (float)random.NextDouble();

            await Clients.All.SendAsync("UpdateEmployeeLocation", employeeLocation);
        }
Example #9
0
 public ActionResult Edit(EmployeeLocation employeeLocation)
 {
     if (ModelState.IsValid)
     {
         _employeeLocationService.Update(employeeLocation);
         return(RedirectToAction("Index"));
     }
     return(View(employeeLocation));
 }
    public void EmployeeLocationHasRightAttributes()
    {
        string           input            = String.Format("({0},{1},{2},{3})", id, correctDate, correctEmployee, location);
        EmployeeLocation employeeLocation = new EmployeeLocation(input);

        Assert.Equal(employeeId, employeeLocation.employee.id);
        Assert.Equal(firstName, employeeLocation.employee.firstname);
        Assert.Equal(lastName, employeeLocation.employee.lastname);
        Assert.Equal(employeeTypeId, employeeLocation.employee.employeeType.id);
    }
Example #11
0
        public EmployeeLocation UpdateEmployeeLocation(EmployeeLocation objEmployeeLocation)
        {
            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                string sql = @"Update EmployeeLocation Set LocationRefNo=@LocationRefNo,LocationName=@LocationName OUTPUT INSERTED.LocationId WHERE LocationId=@LocationId";

                var id = connection.Execute(sql, objEmployeeLocation);
                InsertLoginHistory(dataConnection, objEmployeeLocation.CreatedBy, "Update", "EmployeeLocation", id.ToString(), "0");
                return(objEmployeeLocation);
            }
        }
        async void OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            try
            {
                var item = e.SelectedItem as EmployeeListModel;



                EmployeeLocation empLocal = new EmployeeLocation();


                ActivitySpinner.IsVisible = true;
                HttpClient client = new HttpClient();
                string     url    = Constants.URL + "/employee/GetLocation/" + item.id;
                var        result = await client.GetAsync(url);

                var json = await result.Content.ReadAsStringAsync();

                empLocal = Newtonsoft.Json.JsonConvert.DeserializeObject <EmployeeLocation>(json);



                if (empLocal.JobDesc == "" || empLocal.JobDesc == null)
                {
                    await DisplayAlert("Job", "Employee Has No Active Job", "Okay");
                }
                else
                {
                    bool SetActive = await DisplayAlert("Job", empLocal.JobDesc, "View On Map", "No");

                    if (SetActive == true)
                    {
                        string[] arraypoints;
                        string   location = empLocal.Coordinates;
                        arraypoints = location.Split(',');

                        string lat = arraypoints[0];
                        lattitude = Convert.ToDouble(lat, CultureInfo.InvariantCulture);
                        string lng = arraypoints[1];
                        longitude = Convert.ToDouble(arraypoints[1], CultureInfo.InvariantCulture);

                        await Map.OpenAsync(lattitude, longitude, new MapLaunchOptions { Name = empLocal.JobDesc });
                    }
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Job", "Employee Has No Active Job Catch", "Okay");
            }

            ActivitySpinner.IsVisible = false;
            SetItems();
        }
Example #13
0
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }
            EmployeeLocation employeeLocation = _employeeLocationService.GetById(id.Value);

            if (employeeLocation == null)
            {
                return(StatusCode(StatusCodes.Status404NotFound));
            }
            return(View(employeeLocation));
        }
Example #14
0
        protected void ButtonAddLocation_Click(object sender, EventArgs e)
        {
            //if (Page.IsValid)
            //{
            LabelError.Text = "";
            bool hasError = false;

            PanelError.Visible = false;

            //if (Convert.ToInt32(DropDownListLocation.SelectedValue) == 0)
            //{
            //    LabelError.Text += "Location is required.\n";
            //    PanelError.Visible = true;
            //    hasError = true;
            //}

            if (hasError == false)
            {
                try
                {
                    int companyId = Account.GetAccountByUserName(Page.User.Identity.Name.ToString()).CompanyId;

                    EmployeeLocation.InsertEmployeeLocation(this.employeeId, Convert.ToInt32(DropDownListLocation.SelectedValue), this.Master.LoggedOnAccount, companyId);

                    if (DropDownListLocation.SelectedItem.Text != "CENTRAL")
                    {
                        EmployeeRegion.InsertEmployeeRegion(this.employeeId, Convert.ToInt32(DropDownListLocation.SelectedValue), this.Master.LoggedOnAccount, companyId);
                        //RepStore.InsertRepresentativeStoreByLocationId(this.employeeId, Convert.ToInt32(DropDownListLocation.SelectedValue), this.Master.LoggedOnAccount);

                        BindEmployeeRegionList();
                    }

                    BindEmployeeLocationList();
                }
                catch (System.Data.SqlClient.SqlException sqlEx)
                {
                    LabelError.Text = "";
                    for (int i = 0; i < sqlEx.Errors.Count; i++)
                    {
                        LabelError.Text += (sqlEx.Errors[i].Message + "<br />");
                    }
                    PanelError.Visible = true;
                }
            }
            //}
        }
Example #15
0
        public string GetRefNo(EmployeeLocation objEmployeeLocation)
        {
            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                string RefNo  = "";
                var    result = new EmployeeLocation();

                IDbTransaction trn = connection.BeginTransaction();

                try
                {
                    int internalid = DatabaseCommonRepository.GetInternalIDFromDatabase(connection, trn, typeof(EmployeeLocation).Name, "0", 0);
                    RefNo = "L/" + internalid;
                    trn.Commit();
                }
                catch (Exception ex)
                {
                    trn.Rollback();
                }
                return(RefNo);
            }
        }
Example #16
0
        public ActionResult Permissions(_5Bites.Models.Employee_.Permissions.ViewModel m)
        {
            if (ModelState.IsValid)
            {
                using (var db = new dbEntities())
                {
                    var e = db.Employees.Single(e_ => e_.Id == m.Id);
                    e.IsAdmin = m.IsAdmin;

                    e.EmployeeStores.Clear();
                    e.EmployeeLocations.Clear();
                    db.EmployeeStores.Where(el => el.EmployeeId == e.Id)
                    .ToList().ForEach(el => db.EmployeeStores.Remove(el));
                    db.EmployeeLocations.Where(el => el.EmployeeId == e.Id)
                    .ToList().ForEach(el => db.EmployeeLocations.Remove(el));

                    foreach (var s in m.Stores.Where(s => s.HasAccess))
                    {
                        var es = new EmployeeStore();
                        es.Employee = e;
                        es.StoreId  = s.Id;
                        db.EmployeeStores.Add(es);
                    }

                    foreach (var l in m.Locations.Where(l => l.HasAccess))
                    {
                        var el = new EmployeeLocation();
                        el.Employee   = e;
                        el.LocationId = l.Id;
                        db.EmployeeLocations.Add(el);
                    }

                    db.SaveChanges();
                }

                return(RedirectToAction("Manage", "Employee"));
            }
            return(View());
        }
Example #17
0
        public ActionResult Hire(Models.Employee_.Manage.ViewModel m)
        {
            if (ModelState.IsValid)
            {
                SHA256 sha256 = new SHA256Managed();
                byte[] hashed = sha256.ComputeHash(Encoding.UTF8.GetBytes(m.Hire.Password));

                using (var db = new dbEntities())
                {
                    var e = new Employee();
                    e.Username = m.Hire.Username;
                    e.Password = hashed;
                    e.IsAdmin  = m.Hire.IsAdmin;

                    foreach (var s in m.Hire.Stores.Where(s => s.HasAccess))
                    {
                        var es = new EmployeeStore();
                        es.Employee = e;
                        es.StoreId  = s.Id;
                        e.EmployeeStores.Add(es);
                    }

                    foreach (var l in m.Hire.Locations.Where(l => l.HasAccess))
                    {
                        var el = new EmployeeLocation();
                        el.Employee   = e;
                        el.LocationId = l.Id;
                        e.EmployeeLocations.Add(el);
                    }

                    db.Employees.Add(e);
                    db.SaveChanges();
                }

                return(RedirectToAction("Manage", "Employee"));
            }
            return(View());
        }
Example #18
0
 private void BindEmployeeLocationList()
 {
     GridViewResultEmployeeLocation.DataSource = EmployeeLocation.GetEmployeeLocationListByEmployeeId(this.employeeId);
     GridViewResultEmployeeLocation.DataBind();
 }
        public IActionResult GetEmployeeLocation(string input)
        {
            EmployeeLocation employeeLocation = new EmployeeLocation(input);

            return(Ok(_mapper.Map <EmployeeLocationDto>(employeeLocation)));
        }
Example #20
0
 public async Task UpdateEmployeeLocation(EmployeeLocation employeeLocation)
 {
     await Clients.Group("Administrator").SendAsync("OnUpdateEmployeeLocation", employeeLocation);
 }