public WorkshopSerializer GetWorkshopById(int id) { WorkshopModel workshop = this._workshopDao.GetById(id); WorkshopSerializer result = new WorkshopSerializer(workshop); return(result); }
// GET: Workshop public ActionResult Index() { var model = new List <WorkshopModel>(); using (var db = new MechAppProjectEntities()) { var workshops = db.Workshops.ToList(); foreach (var workshop in workshops) { var workshopModel = new WorkshopModel() { WorkshopId = workshop.WorkshopId, City = workshop.City, Email = workshop.Email, PhoneNbr = workshop.PhoneNbr, Street = workshop.Street, StreetNbr = workshop.StreetNbr, WorkshopName = workshop.WorkshopName, ZipCode = workshop.ZipCode }; model.Add(workshopModel); } } return(View(model)); }
public ActionResult WorkshopRegister(WorkshopModel objWorkshopModel) { if (ModelState.IsValid) { Workshop objWorkshop = new Workshop(); objWorkshop.Login = objWorkshopModel.Login; if (objMechAppProjectEntities.Workshops.Any(x => x.Login == objWorkshopModel.Login)) { ViewBag.DuplicateMessageLogin = "******"; return(View("WorkshopRegister", objWorkshopModel)); } objWorkshop.Password = objWorkshopModel.Password; objWorkshop.Email = objWorkshopModel.Email; if (objMechAppProjectEntities.Workshops.Any(x => x.Email == objWorkshop.Email)) { ViewBag.DuplicateMessageEmail = "Ten Email jest już zajęty!!"; return(View("WorkshopRegister", objWorkshopModel)); } objWorkshop.WorkshopName = objWorkshopModel.WorkshopName; objWorkshop.OwerName = objWorkshopModel.OwnerName; objWorkshop.City = objWorkshopModel.City; objWorkshop.Street = objWorkshopModel.Street; objWorkshop.StreetNbr = objWorkshopModel.StreetNbr; objWorkshop.ZipCode = objWorkshopModel.ZipCode; objWorkshop.PhoneNbr = objWorkshopModel.PhoneNbr; objMechAppProjectEntities.Workshops.Add(objWorkshop); objMechAppProjectEntities.SaveChanges(); ModelState.Clear(); ViewBag.SuccessMessage = "Warsztat dodany poprawnie"; return(RedirectToAction("Index", "Home")); } return(View()); }
public WorkshopModel CreateWorkshop(WorkshopModel workshop) { if (workshop.Id == null) { var valid = _workshops.OrderByDescending(a => a.Id).FirstOrDefault(); if (valid != null) { workshop.Id = valid.Id + 1; } else { workshop.Id = 1; } if (workshop.Status == null || workshop.Status == "Scheduled") { workshop.Status = "Scheduled"; } else { throw new WrongOperationException("Status has to be Scheduled or Postponed or Cancelled"); } _workshops.Add(workshop); } else { _workshops.Add(workshop); } return(workshop); }
public String Create(WorkshopModel workshopModel) { using (var connection = new MySqlConnection(Constant.getDatabaseConnectionString())) { /* * FactoryModel factory = connection * .Query<FactoryModel>("SELECT * FROM factory WHERE factoryName=@fn", new * { * fn = workshopModel.Factory * }).FirstOrDefault(); */ FactoryModel factory = connection .Query <FactoryModel>("SELECT * FROM factory WHERE factoryName=@fn AND factory.city IN (SELECT city.id FROM city WHERE city.cityName=@cn)", new { fn = workshopModel.Factory, cn = workshopModel.City }).FirstOrDefault(); int rows = connection .Execute( "INSERT INTO workshop(workshopName, workshopPhoneNumber, workshopAddress, remark, factory) VALUES (@wn, @wpn, @wa, @r, @f)", new { wn = workshopModel.WorkshopName, wpn = workshopModel.WorkshopPhoneNumber, wa = workshopModel.WorkshopAddress, r = workshopModel.Remark, f = factory.Id }); return(rows == 1 ? "success" : "error"); } }
public ActionResult WorkshopProfileEdit(WorkshopModel model) { var workshopSession = Session["LoginWorkshop"] as SessionModel; if (workshopSession != null) { using (var db = new MechAppProjectEntities()) { var workshopModel = db.Workshops.FirstOrDefault(x => x.WorkshopId == workshopSession.WorkshopId); workshopModel.Password = model.Password; workshopModel.Email = model.Email; workshopModel.WorkshopName = model.WorkshopName; workshopModel.OwerName = model.OwnerName; workshopModel.PhoneNbr = model.PhoneNbr; workshopModel.City = model.City; workshopModel.Street = model.Street; workshopModel.StreetNbr = model.StreetNbr; workshopModel.ZipCode = model.ZipCode; db.SaveChanges(); } } return(RedirectToAction("WorkshopProfile")); }
public ActionResult WorkshopProfileEdit() { { var model = new WorkshopModel(); var workshopSession = Session["LoginWorkshop"] as SessionModel; if (workshopSession != null) { using (var db = new MechAppProjectEntities()) { var workshop = db.Workshops.FirstOrDefault(x => x.WorkshopId == workshopSession.WorkshopId); model.Login = workshop.Login; model.Password = workshop.Password; model.Email = workshop.Email; model.WorkshopName = workshop.WorkshopName; model.OwnerName = workshop.OwerName; model.City = workshop.City; model.Street = workshop.Street; model.StreetNbr = workshop.StreetNbr; model.ZipCode = workshop.ZipCode; model.PhoneNbr = workshop.PhoneNbr; } return(View(model)); } return(View()); } }
public async Task Update(WorkshopModel model) { const string query = @"UPDATE workshops SET name=@name WHERE id=@id;"; await using var conn = BaseRepository.Connection(); await conn.OpenAsync(); await conn.QueryAsync(query, model); }
public async Task Create(WorkshopModel model) { const string query = @"INSERT INTO workshops('name') VALUES (@name);"; await using var conn = BaseRepository.Connection(); await conn.OpenAsync(); var result = conn.Query(query, model); }
public String CreateNewWorkshop(WorkshopSerializer workshopSerializer) { WorkshopModel workshopModel = new WorkshopModel(); workshopModel.WorkshopName = workshopSerializer.workshopName; workshopModel.WorkshopPhoneNumber = workshopSerializer.workshopPhoneNumber; workshopModel.WorkshopAddress = workshopSerializer.workshopAddress; workshopModel.Remark = workshopSerializer.remark; workshopModel.Factory = workshopSerializer.factory; return(this._workshopDao.Create(workshopModel)); }
public String UpdateWorkshop(int id, WorkshopSerializer workshopSerializer) { WorkshopModel workshopModel = new WorkshopModel(); workshopModel.Id = workshopSerializer.id; workshopModel.WorkshopName = workshopSerializer.workshopName; workshopModel.WorkshopPhoneNumber = workshopSerializer.workshopPhoneNumber; workshopModel.WorkshopAddress = workshopSerializer.workshopAddress; workshopModel.Remark = workshopSerializer.remark; workshopModel.Factory = workshopSerializer.factory; return(this._workshopDao.Update(id, workshopModel)); }
bool IWorkshopService.deleteWorkshop(int id) { bool resultResponse = true; WorkshopModel result = _DataWorkshops.getWorkshop(id); if (result == null) { resultResponse = false; } _DataWorkshops.deleteWorkshop(id); return(resultResponse); }
public String Update(int id, DeviceModel deviceModel) { using (var connection = new SqlConnection(Constant.getDatabaseConnectionString())) { CityModel city = connection.Query <CityModel>( "SELECT * FROM city WHERE city.cityName=@cn", new { cn = deviceModel.City }).FirstOrDefault(); FactoryModel factory = connection.Query <FactoryModel>( "SELECT * FROM factory WHERE factory.factoryName=@fn", new { fn = deviceModel.Factory }).FirstOrDefault(); WorkshopModel workshop = connection.Query <WorkshopModel>( "SELECT * FROM workshop WHERE workshop.workshopName=@wn", new { wn = deviceModel.Workshop }).FirstOrDefault(); int rows = connection .Execute( "UPDATE device " + "SET hardwareDeviceID=@hdid, " + "deviceName=@dn, " + "city=@c, " + "factory=@f, " + "workshop=@w, " + "deviceState=@ds, " + "imageUrl=@iu, " + "gatewayId=@gid, " + "mac=@m, " + "deviceType=@dt, " + "remark=@r, " + "updateTime=CURRENT_TIMESTAMP " + "WHERE device.id=@deviceId", new { deviceId = deviceModel.Id, hdid = deviceModel.HardwareDeviceId, dn = deviceModel.DeviceName, c = city.Id, f = factory.Id, w = workshop.Id, ds = deviceModel.DeviceState, iu = deviceModel.ImageUrl, gid = deviceModel.GatewayId, m = deviceModel.Mac, dt = deviceModel.DeviceType, r = deviceModel.Remark }); return(rows == 1 ? "success" : "error"); } }
public WorkshopSerializer(WorkshopModel workshopModel) { this.id = workshopModel.Id; this.workshopName = workshopModel.WorkshopName; this.workshopPhoneNumber = workshopModel.WorkshopPhoneNumber; this.workshopAddress = workshopModel.WorkshopAddress; this.remark = workshopModel.Remark; this.createTime = workshopModel.CreateTime .ToString(Constant.getDateFormatString()); this.updateTime = workshopModel.UpdateTime .ToString(Constant.getDateFormatString()); this.factory = workshopModel.Factory; }
public async Task Consume(ConsumeContext <IWorkshopAdded> context) { var workshop = new WorkshopModel(context.Message.Id) { Name = context.Message.Name, Status = context.Message.Status, CityId = BaseModel.MakeId(typeof(CityModel), context.Message.CityId), }; _context.Workshops.Add(workshop); await _context.SaveChangesAsync(); _context.Dispose(); }
public void SetProperties() { TeacherToAdd = new WorkshopTeacher { WorkshopID = WorkshopDetails.WorkshopID }; ModelToAdd = new WorkshopModel { WorkshopID = WorkshopDetails.WorkshopID }; ParticipantToAdd = new WorkshopParticipant { WorkshopID = WorkshopDetails.WorkshopID }; }
public ActionResult <bool> PutWorkshop([FromRoute] int id, [FromBody] WorkshopModel workshops) { try { var res = _workshopServices.EditWorkshop(id, workshops); return(Ok(res)); } catch (NotFoundItemException ex) { return(this.StatusCode(StatusCodes.Status404NotFound, ex.Message)); } catch (Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public ActionResult <WorkshopModel> PostWorkshop([FromBody] WorkshopModel workshops) { try { var newworkshop = _workshopServices.CreateWorkshop(workshops); return(Created($"/workshop/{newworkshop.Id}", newworkshop)); } catch (WrongOperationException ex) { return(this.StatusCode(StatusCodes.Status409Conflict, ex.Message)); } catch (Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public String Create(DeviceModel deviceModel) { using (var connection = new MySqlConnection(Constant.getDatabaseConnectionString())) { CityModel city = connection.Query <CityModel>( "SELECT * FROM city WHERE city.cityName=@cn", new { cn = deviceModel.City }).FirstOrDefault(); FactoryModel factory = connection.Query <FactoryModel>( "SELECT * FROM factory WHERE factory.factoryName=@fn", new { fn = deviceModel.Factory }).FirstOrDefault(); WorkshopModel workshop = connection.Query <WorkshopModel>( "SELECT * FROM workshop WHERE workshop.workshopName=@wn", new { wn = deviceModel.Workshop }).FirstOrDefault(); GatewayModel gateway = connection.Query <GatewayModel>("select * from gateway where gatewayName=@gn", new { gn = deviceModel.GatewayId }).FirstOrDefault(); int deviceType = connection.Query <int>( "select id from config where configTag=@ct and configValue=@cv", new { ct = "deviceType", cv = deviceModel.DeviceType }).FirstOrDefault(); int rows = connection.Execute( "INSERT INTO " + "device(hardwareDeviceID, deviceName, city, factory, workshop, deviceState, imageUrl, gatewayId, mac, deviceType, remark)" + " VALUES (@hdid, @dn, @c, @f, @w, @ds, @iu, @gid, @m, @dt, @r)", new { hdid = deviceModel.HardwareDeviceId, dn = deviceModel.DeviceName, c = city.Id, f = factory.Id, w = workshop.Id, ds = deviceModel.DeviceState, iu = deviceModel.ImageUrl, gid = gateway.Id, m = deviceModel.Mac, dt = deviceType, r = deviceModel.Remark }); return(rows == 1 ? "success" : "error"); } }
public WorkshopModel editWorkShop(int id, WorkshopModel workshop) { WorkshopModel result = null; if (id == workshop.id) { var workShopToEdit = _DataWorkshops.getWorkshop(id); if (workShopToEdit != null) { workShopToEdit.id = workshop.id; workShopToEdit.name = workshop.name; workShopToEdit.status = workshop.status; } result = workShopToEdit; } return(result); }
public bool EditWorkshop(int Id, WorkshopModel workshop) { var newWorkshop = _workshops.SingleOrDefault(c => c.Id == Id); var ans = false; if (newWorkshop != null) { newWorkshop.Id = workshop.Id; newWorkshop.Name = workshop.Name; newWorkshop.Status = workshop.Status; ans = true; } else { throw new NotFoundItemException("The workshop was not found in the DB"); } return(ans); }
public async Task PostSuccess(String WorkshopName, String remark, String WorkshopPhoneNumber, String WorkshopAddress, String Factory) { var data = new WorkshopModel { WorkshopName = WorkshopName, Remark = remark, WorkshopPhoneNumber = WorkshopPhoneNumber, WorkshopAddress = WorkshopAddress, Factory = Factory }; var content = new StringContent(data.ToJson(), Encoding.UTF8, "text/json"); var response = await this._httpClient.PostAsync("api/workshop", content); var result = response.Content.ReadAsStringAsync().Result; Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.Contains("\"c\":200,\"m\":\"success\",\"d\":\"success\"", result); }
public async Task <IActionResult> Workshop(int id) { var model = new WorkshopModel { ShowSpeakerInfo = true }; model.Workshop = _workshopService.Value.GetById(id); if (model.Workshop == null) { return(RedirectToAction("Workshops")); } model.TicketsLeft = model.Workshop.MaxTickets - (await AppFactory.TicketService.Value.GetWorkshopTicketsAsync(id)).Count; if (model.TicketsLeft < 0) { model.TicketsLeft = 0; } return(View(model)); }
public WorkshopModel GetById(int id) { using (var connection = new MySqlConnection(Constant.getDatabaseConnectionString())) { WorkshopModel workshopModel = connection .Query <WorkshopModel>("SELECT workshop.id, " + "workshopName, " + "workshopPhoneNumber, " + "workshopAddress, " + "workshop.remark, " + "workshop.createTime, " + "workshop.updateTime, " + "factory.factoryName AS factory " + "FROM workshop JOIN factory " + "ON workshop.factory=factory.id " + "WHERE workshop.id=@workshopId", new { workshopId = id }).FirstOrDefault(); return(workshopModel); } }
public String Update(int id, GatewayModel gatewayModel) { using (var connection = new SqlConnection(Constant.getDatabaseConnectionString())) { CityModel city = connection.Query <CityModel>( "SELECT * FROM city WHERE city.cityName=@cn", new { cn = gatewayModel.City }).FirstOrDefault(); FactoryModel factory = connection.Query <FactoryModel>( "SELECT * FROM factory WHERE factory.factoryName=@fn", new { fn = gatewayModel.Factory }).FirstOrDefault(); WorkshopModel workshop = connection.Query <WorkshopModel>( "SELECT * FROM workshop WHERE workshop.workshopName=@wn", new { wn = gatewayModel.Workshop }).FirstOrDefault(); int rows = connection.Execute( "UPDATE gateway SET hardwareGatewayID=@hgid, gatewayName=@gn, city=@c, factory=@f, workshop=@w, gatewayType=@gt, gatewayState=@gs, imageUrl=@iu, remark=@r, updateTime=CURRENT_TIMESTAMP WHERE id=@gatewayId", new { gatewayId = id, hgid = gatewayModel.HardwareGatewayId, gn = gatewayModel.GatewayName, c = city.Id, f = factory.Id, w = workshop.Id, gt = gatewayModel.GatewayType, gs = gatewayModel.GatewayState, iu = gatewayModel.ImageUrl, r = gatewayModel.Remark }); return(rows == 1 ? "success" : "error"); } }
public String Create(GatewayModel gatewayModel) { using (var connection = new SqlConnection(Constant.getDatabaseConnectionString())) { CityModel city = connection.Query <CityModel>( "SELECT * FROM city WHERE city.cityName=@cn", new { cn = gatewayModel.City }).FirstOrDefault(); FactoryModel factory = connection.Query <FactoryModel>( "SELECT * FROM factory WHERE factory.factoryName=@fn", new { fn = gatewayModel.Factory }).FirstOrDefault(); WorkshopModel workshop = connection.Query <WorkshopModel>( "SELECT * FROM workshop WHERE workshop.workshopName=@wn", new { wn = gatewayModel.Workshop }).FirstOrDefault(); int rows = connection.Execute( "INSERT INTO gateway(hardwareGatewayID, gatewayName, city, factory, workshop, gatewayType, gatewayState, imageUrl, remark)" + " VALUES(@hgid, @gn, @c, @f, @w, @gt, @gs, @iu, @r)", new { hgid = gatewayModel.HardwareGatewayId, gn = gatewayModel.GatewayName, c = city.Id, f = factory.Id, w = workshop.Id, gt = gatewayModel.GatewayType, gs = gatewayModel.GatewayState, iu = gatewayModel.ImageUrl, r = gatewayModel.Remark }); return(rows == 1 ? "success" : "error"); } }
static void InitData() { WorkshopModel.Init(); FieldInfo fieldInfo; object[] attribArray; DescriptionAttribute attrib; resourceNameMapping = new Dictionary <ResourceType, string>(); foreach (ResourceType type in Enum.GetValues(typeof(ResourceType))) { fieldInfo = type.GetType().GetField(type.ToString()); attribArray = fieldInfo.GetCustomAttributes(false); attrib = (DescriptionAttribute)attribArray[0]; resourceNameMapping.Add(type, attrib.Description); } resourceTotalYieldNumMapping = new Dictionary <ResourceType, int>(); resourceNames = new List <string>(); resourceNeedBaseResMapping = new Dictionary <ResourceType, int>(); resourceNeedSecondsMapping = new Dictionary <ResourceType, int>(); ResourceRelationshipData relation; for (int i = 0; i < WorkshopModel.Relationships.Count; i++) { relation = WorkshopModel.Relationships[i]; resourceNames.Add(getResourceName(relation.Type)); if (!resourceTotalYieldNumMapping.ContainsKey(relation.Type)) { resourceTotalYieldNumMapping.Add(relation.Type, relation.YieldNum); } resourceNeedBaseResMapping.Add(relation.Type, getNeedWheatNum(relation.Type)); resourceNeedSecondsMapping.Add(relation.Type, getBeedSecond(relation.Type)); } }
public String Update(int id, WorkshopModel workshopModel) { using (var connection = new MySqlConnection(Constant.getDatabaseConnectionString())) { FactoryModel factory = connection .Query <FactoryModel>("SELECT * FROM factory WHERE factoryName=@fn", new { fn = workshopModel.Factory }).FirstOrDefault(); int rows = connection .Execute( "UPDATE workshop SET workshopName=@wn, workshopPhoneNumber=@wpn, workshopAddress=@wa, remark=@r, factory=@f, updateTime=CURRENT_TIMESTAMP WHERE id=@workshopId", new { wn = workshopModel.WorkshopName, wpn = workshopModel.WorkshopPhoneNumber, wa = workshopModel.WorkshopAddress, r = workshopModel.Remark, f = factory.Id, workshopId = id }); return(rows == 1 ? "success" : "error"); } }
public void addWorkshop(WorkshopModel workshop) { workshops.Add(workshop); }
public ActionResult Search(string sortOrder, string currentFilter, string searchString, int?page) { var model = new List <WorkshopModel>(); var workshops = db.Workshops.ToList(); foreach (var workshop in workshops) { var workshopModel = new WorkshopModel() { WorkshopId = workshop.WorkshopId, City = workshop.City, Email = workshop.Email, PhoneNbr = workshop.PhoneNbr, Street = workshop.Street, StreetNbr = workshop.StreetNbr, WorkshopName = workshop.WorkshopName, ZipCode = workshop.ZipCode }; model.Add(workshopModel); } ViewBag.CurrentSort = sortOrder; ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "name_desc" : ""; ViewBag.DateSortParm = sortOrder == "Date" ? "date_desc" : "Date"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; var workshopsView = from w in model select w; if (!String.IsNullOrEmpty(searchString)) { workshopsView = workshopsView.Where(w => w.WorkshopName.ToLower().Contains(searchString.ToLower()) || w.City.ToLower().Contains(searchString.ToLower()));; } switch (sortOrder) { case "name_desc": workshopsView = workshopsView.OrderByDescending(s => s.WorkshopName); break; default: // Name ascending workshopsView = workshopsView.OrderBy(s => s.WorkshopName); break; } int pageSize = 3; int pageNumber = (page ?? 1); return(View(workshopsView.ToPagedList(pageNumber, pageSize))); }